I’m trying to create a universal handler for my buttons,
but the following code doesn’t seem to recognize the event targets,
and instead spits out the target.toString() == the current page URL?
html:
<a id="button1" href="#"></a>
<a id="button2" href="#"></a>
jquery/javascript:
function myHandler(e) {
if (e.target == $("#button1"))
alert("Button 1 clicked");
else if (e.target == $("#button2"))
alert("Button 2 clicked");
else
alert(e.target.toString());
}
$("#button1").click(myHandler);
$("#button2").click(myHandler);
your code cannot work because you are comparing the target event with a jQuery object
Live example: http://jsfiddle.net/fcalderan/7b53z/