-5

Trying to add more fields to a dynamically generated form. User clicks 'add multiple choice' button, a multiple choice form is generated. Then they should be able to add more 'wrong answer' fields to this form when clicked, but it's not working. I know jquery's .live() is the right way to do it, but I can't get it to work.

$('button.btn-wrong').live('click', function(e) {
    alert("yay!");
})

http://jsfiddle.net/SWCE4/

Working jsfiddle http://jsfiddle.net/SWCE4/4/

visevo
  • 761
  • 7
  • 23

3 Answers3

2

live() was deprecated in jQuery 1.7 and removed in version 1.9 . You need to use .on() instead.

$(document).on('click', 'button.btn-wrong', function(e) {
    alert("yay!");
})
karthikr
  • 87,486
  • 24
  • 182
  • 182
0

$.live was deprecated on jQuery 1.7. Use $.on , for sample:

$('button.btn-wrong').on('click', function(e) {
    alert("yay!");
});
Felipe Oriani
  • 35,246
  • 17
  • 121
  • 176
0

http://api.jquery.com/live/

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().

$(document).on("click", "button.btn-wrong", function(event) {
    alert("yay!");
});
iambriansreed
  • 20,961
  • 6
  • 58
  • 73