Friday, 6 September 2013

Alert does not appear for links inserted by JavaScript

Alert does not appear for links inserted by JavaScript

I'm working with a large codebase, and I'm trying to write some JQuery so
that whenever the user clicks on a link (i.e. the a tag), there's an
alert. This is what I wrote:
$(document).ready(function() {
alert("hey ho!");
$("a").click(function(event){
alert("Hello!");
});
});
The "hey ho!" alert shows up, so JQuery is working. Now, the links in this
file are not actually in the HTML code, but rather they are inserted by
some other JavaScript. I can print them out as DOM elements and see them
on my console:
<a style="..." href="...">
They are internal links, and when I click on them, they jump to the
correct place. However, there is no alert. What might be the problem? How
could I debug this?

No comments:

Post a Comment