I am new and I was wondering if you might be able to help. I have come across a situation that I have not been able to figure out for the last few days.
I have a dynamic div on my document that looks like this <div id="map_25_5">Map</div>
In my javascript file I have
$('[id^="map_"]').click(function(){
alert('hello');
});
When the document is loaded ... even if I click on the link nothing is detected but if I use for example firebug and actually enter that in the console ... then every link start to be detected.
Has anyone run into this before?
I am using Jquery 2.1 and I have tried the "on" and "click" functions and still doesn't get registered... but when I add it to the console and run it works. I Dont think this is an issue of using a deprecated handler with the wrong version of Jquery.
I was able to find the answer to this. Although the original review was not correct, I am going to document this here in case someone else has this issue. This issue can be resolved by using event delegation. Please read more by following this link: jQuery click handler function does not fire on element added after DOM load