Solved

Rebind events

Posted on 2014-10-23
1
97 Views
Last Modified: 2014-10-23
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
Comment
Question by:tonelm54
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40399662
$(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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question