I don’t know if I have forgotten how to do so or if it’s a bug, but I just can’t find the caller’s reference in the "click" event using jQuery.
I’m doing the following:
$(document).ready(function() {
$('#parent a.item').click(doSomething);
});
function doSomething(e) {
// Alerts for demostrational purposes only
alert(e.target);
alert(e.currentTarget);
alert(this);
alert($(this)[0]);
}
All the alerts show the hyperlink´s href attribute(page URL + ‘#’).
Am I doing something wrong?
Notes:
Using jQuery 1.4.2.
It’s because you’re alerting so you’re seeing the string representation (since
alert()takes a string)…which for an anchor is thehref. You could do this for example:You can try it out/play with it here, note that
thisande.targetaren’t always the same, if the click came from a child element, they’ll be different.