Jquery: Selector Can't Find Class?
Solution 1:
use jQuery live():
$('.Entf').live('click',function(event){
alert("Thanks for visiting!");
});
using live enables jQuery use callbacks on selectors that are dynamically created by javascript
Solution 2:
Because the element is getting created after the handlers are bound, it's not registering. You need something like this:
$("body").delegate(".Entf", "click", function() { //function here });
Solution 3:
Use jQuery on() in jQuery 1.7+
$(document).on("click",".Entf",function(event){
alert("Thanks for visiting!");
});
Use jQuery delegate() in jQuery 1.4.3+:
$(document).delegate(".Entf", "click", function(event){
alert("Thanks for visiting!");
});
And use jQuery live() in jQuery 1.3:
$('.Entf').live('click',function(event){
alert("Thanks for visiting!");
});
Solution 4:
When you have generated content, you need to bind the button, ie, after you have generated the content, do:
$('.Entf').click(function(event){
alert("Thanks for visiting!");
});
again.
Edit: As pointed out by Neal, be careful when doing it this method. The reason as that it will bind to ALL .Entf elements, not just the new ones, causing multiple click events. See http://jsfiddle.net/R9Kb4/2/ for an example of how to create and bind things without having to deal with live() or with multiple binding.
Post a Comment for "Jquery: Selector Can't Find Class?"