How can events be prevented from stopping to work after an ajax request?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Feb 22, 2018

 

There are two ways to handle this issue:
Use of event delegation: The event delegation technique works on principle by exploiting the event bubbling. It uses event bubbling to capture the events on elements which are present anywhere in the domain object model. In jquery the user can make use of the live and die methods for the events delegation which contains a subset of event types.
For example. handling even delegation, handling of clicks on any <a> element:

$('#mydiv').click(function(e){
if( $(e.target).is('a') )
fn.call(e.target,e);
});
$('#mydiv').load('my.html')

Event rebinding usage: When this method is used it requires the user to call the bind method and the added new elements.

$('a').click(fn);
$('#mydiv').load('my.html',function(){
$('#mydiv a').click(fn);
});

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    JQuery Interview Questions

    What is jQuery?

    jQuery is a lightweight JavaScript library which gives a quick and simple method for HTML DOM traversing and manipulati..

    JQuery Interview Questions

    What are the advantages of JQuery ?

    There are many advantages of JQuery. Some of them are :It is more like a JavaScript enhancement so there is no overhea..

    JQuery Interview Questions

    What are the different type of selectors in Jquery?

    There are 3 types of selectors in JqueryCSS Selector XPath Selector Custom Selector..