I have a php page that prints out a div having multiple anchor tags with different IDs. Here is a sample code:
echo "<div id=\"pageLinks\">";
echo " <a href=\"javascript:;\" id=\"1\"><<</a> ";
echo "another link...."
echo "</div">;
The javascript code that should listen for the click event is the following:
$(document).ready(function(){
$("div#pageLinks a").click(function(){
alert("clicked");
});
});
but it’s apparently not working (I cannot see the “clicked” alert).
Can someone help me?
Your HTML source code is totally broken. You should use
<instead of<and close your last div properly.Your javascript code btw is working, check it here: http://jsfiddle.net/raszi/H9dnE/3/
UPDATE
A possible better code:
PHP:
Javascript:
Can be checked here: http://jsfiddle.net/raszi/p3Ug2/