Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 116
  • Last Modified:

Rebind events

Is is possible to rebind events?

For example if I assign on document load:-
$(".testButtons").click(function () { alert("hi"); });

Open in new window


And then I dynamically add a button with the class '.testButtons' then the event isnt attached, but I want it to.

For example jsFiddle

Any ideas how I can rebind?

Thank you
0
tonelm54
Asked:
tonelm54
1 Solution
 
leakim971PluritechnicianCommented:
$(document).on("click", ".testButtons", function () { alert("hi"); }); // ifyou've jQuery 1.9 or greater
$(".testButtons").live("click", function () { alert("hi"); }); // if you've jQuery version lower than 1.9

More infos :
http://api.jquery.com/live/
http://api.jquery.com/on/
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now