View Full Version : jquery question function
earth2mac
03-18-2009, 12:29 AM
I am using a script to change content in a window. I need the html contnet in window to be up by default. With this it's only up when you click link. What do I need to add to this?
<script type="text/javascript">
$(document).ready(function() {
$('#links a').click(function() {
var url=$(this).attr('href');
$('#headlines').load(url + ' #newsItems');
return false;
});
});
</script>
TinyScript
03-18-2009, 12:50 AM
there has to be a way to set the variable beforehand. Where's the script? Find out what names are used, find out the one you want for default, set it to that one to begin with, and you're done.
Eldarrion
03-18-2009, 03:51 PM
Or just add one line like this:
<script type="text/javascript">
$(document).ready(function() {
$('#links a').click(function() {
var url=$(this).attr('href');
$('#headlines').load(url + ' #newsItems');
return false;
});
$('#links a').click();
});
</script>
Essentially triggers the click event on the link in question. It can be changed otherwise too... like so:
<script type="text/javascript">
$(document).ready(function() {
var url=$('#links a').attr('href');
$('#headlines').load(url + ' #newsItems');
});
</script>
But what you use is really up to you. The second one will have no effect if people actually do decide to click on the link, and it will follow the link, so the first solution might be the better choice, depending on what you really want to do.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.