Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

its weird that all my jquery events turn unresponsive after a ajax call. Im a load function call and once the jsp reloads all the events just do not respond. any help ?

the following is the code which triggers the function call.

$('#personTypeId').on('change', function() {
    var selectId = document.getElementById("personTypeId").value;
    if (selectId == 1 || selectId == 4 || selectId == 8) {
        $("#directoryFilter").load("directory/filters #directoryFilter",{"selectId" : selectId  });

    }
});
share|improve this question
    
look at event delegation – Arun P Johny Apr 28 '14 at 3:03
    
i tried. but could not figure where im going wrong – user2707760 Apr 28 '14 at 3:03
    
can you share a sample event handler which is not triggering – Arun P Johny Apr 28 '14 at 3:04
    
See here and here for how to use the delegated version of .on(). – jfriend00 Apr 28 '14 at 3:04
    
you need to do something like $("#directoryFilter").on('event-name', 'target-eleement-selector', function(){}) – Arun P Johny Apr 28 '14 at 3:04
up vote 0 down vote accepted
$(document).on("change", "#personTypeId", function(){
    var selectId = document.getElementById("personTypeId").value;
    if (selectId == 1 || selectId == 4 || selectId == 8) {
            $("#directoryFilter").load("directory/filters #directoryFilter",{"selectId" : selectId  });
    }
});
share|improve this answer
    
i want the a on change event to trigger for the selector #personTypeid but in the example you showed we are not even mentioning it. Im a bit new to jquery. correct me if im wrong. sorry – user2707760 Apr 28 '14 at 3:10
    
Checkout the updated answer – Navneil Naicker Apr 28 '14 at 3:10
    
sorry i dont see any thing updated. – user2707760 Apr 28 '14 at 3:14
    
$(document).on("change", "#directoryFilter", function(){ /* Your code goes here..*/ }); – Navneil Naicker Apr 28 '14 at 3:15
    
The event is "change". On change that is.. – Navneil Naicker Apr 28 '14 at 3:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.