I am very new to jQuery and am making a history API-ish script in jQuery so only the needed info in a new page loads on a click. The problem is I don’t know how to place the var in the handler, atleast I think its called the handler. It will definitely be a simple thing.
$("a#click").click(function() {
var addressValue = $(this).attr("href");
$("#main").load("addressValue #load");
return false;
});
If you use:
It should work; the problem was that you were placing the variable into the string, so it was being evaluated as the variable-name, not the variable concatenated with the
' #load'string.Also, for the
hrefit’s slightly faster to avoid invoking jQuery, and just use the native DOM approach (it’s a micro optimisation, but it’s just slightly cheaper).It’s worth noting that
this.hrefdoes (sometimes-problematically) retrieve the absolute path implied by whatever value is, strictly speaking, inside of thehrefattribute, including the domain. Whereas the jQuery approach simply retrieves whatever is in the attribute, so: