0

I'm using an AJAX request to add some pages into my JQuery mobile site. But after adding buttons I cannot access those using the class I set before. Is there a way to inform JQuery that I updated the DOM and that there are new buttons with the class?

adding the button:

echo "<a data-role=\"button\" class=\"delbtn\" data-transition=\"fade\" data-icon=\"delete\">Delete</a>";

accessing the button:

$(".delbtn").click(function(){
  //some action.. 
});
minils
  • 7
  • 1
  • 6

2 Answers2

0

you have to bind a live event handler (jQuery ON) because your buttons are added dynamically

$(document).on("click",".delbtn", function(){
  //some action.. 
});
ilyes kooli
  • 11,959
  • 14
  • 50
  • 79
0

http://jsfiddle.net/MEXhE/1/

$(".delbtn").live('click',function(){
    alert("clicked");
});
root
  • 1,573
  • 3
  • 23
  • 38
  • where's the difference to `on()` ? – minils May 21 '12 at 14:40
  • if you're using jquery 1.7 onwards you should use `.on` instead of `.live` http://stackoverflow.com/questions/8042576/whats-the-difference-between-jquery-live-and-on – root May 21 '12 at 23:18