I have the bellow code, I wish to create an IF statement so the loadScript function is only called for a specific HREF. But when I try and alert the value of the href it returns “Undefined”…
Many Thanks,
J
$(document).ready(function()
{
$('.jNav').click(function()
{
$('#sandbox').load($(this).attr('href'),function()
{
alert("From here " + $(this).attr('href') + " to here.");
loadScript();
});
return false;
});
});
Your issue is just scoping. In your load() callback, this refers to the element you’re calling load() on, which happens to be
$('#sandbox'), and thus: no href. Usually what I do is something like this:Doing this ensures that you can still get to the thing that you clicked from inside the load() callback.