Solved

Rebind events

Posted on 2014-10-23
1
88 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now