As you can gather from the title, I’m using JQuery’s .click function to handle someone clicking a link in my navigation bar.
When the link is clicked JQuery loads in a specific section of a different html file into the content div of the main page. The code I’ve came up does what I want, but I’m a novice in JQuery, and I’m wondering how to do this without having to create a variable to hold everything.
$(document).ready(function(){
$('#content').load('bio.html .content'); // fill #content when page loads
$('#heading a').click(function(){
var x = $(this).attr('href') + " .content";
$('#content').load(x);
return false;
});
});
I was trying to figure out how to do something like $(‘#content’).load($(this.attr(‘href’)) .content);. However, I couldn’t get it to work properly, so I ended up creating the variable you see above, which is fine, but I’d like to keep things concise.
Any help or advice would be appreciated.
Is…
… what you’re trying to do?