1

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

Community
  • 1
  • 1
Rick Rod
  • 11
  • 2
  • 3
    The element is probably not ready when the document is loaded. See [delegated event handling](http://stackoverflow.com/q/203198/1612146). – George Jul 17 '15 at 15:00
  • Maybe the code isn't yet loaded. Could you please post HTML of where and how the script is being added to the page? – codehitman Jul 17 '15 at 15:01
  • _and actually enter that in the console ... then every link start to be detected._. Sounds like a not ready thing ;) – putvande Jul 17 '15 at 15:02

0 Answers0