Solved

Rebind events

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
The viewer will learn how to dynamically set the form action using jQuery.
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)

777 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