0

I want to bind a click even to the dynamically added span elements to a node on my page. I wrote the bind event for a single static element and it works fine -

function clickSpan(domNode){
   $(domNode).find("span").bind("click", function(){
      alert("span clicked");
   });
}

I tried writing the same for dynamically added elements and changed the "bind" to the "on" method. Somehow this doesn't work for the dynamically added span elements. How do i make the dynamically added span elements to respond to clicks?

Dan
  • 801
  • 2
  • 14
  • 29

1 Answers1

2

Try out this code:

$('#parent_selector').on('click', 'span', function(){
    alert("here");
});
Bla...
  • 7,228
  • 7
  • 27
  • 46