How can events be prevented to work after an ajax request?
Submitted by: Administratorhere are two ways to handle this issue:
1. 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 ex. 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')
2. Event rebinding usage : When this method is used it requires the user to call the bind method and the added new elements.
For ex.
$('a').click(fn);
$('#mydiv').load('my.html',function()
{
$('#mydiv a').click(fn);
});
Submitted by:
1. 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 ex. 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')
2. Event rebinding usage : When this method is used it requires the user to call the bind method and the added new elements.
For ex.
$('a').click(fn);
$('#mydiv').load('my.html',function()
{
$('#mydiv a').click(fn);
});
Submitted by:
Read Online JQuery Programmer Job Interview Questions And Answers
Top JQuery Programmer Questions
☺ | What are jQuery Selectors? Give some examples? |
☺ | How to get the direct parent of an element using jQuery? |
☺ | How to set the style property of an element using jQuery? |
☺ | How to get the height of an element using jQuery? |
☺ | Explain the common methods of sending a request to a server? |
Top Scripting language Categories
☺ | AngularJS Interview Questions. |
☺ | Ext-JS Interview Questions. |
☺ | Dojo Interview Questions. |
☺ | Expert Developer JavaScript Interview Questions. |
☺ | jQuery Mobile Interview Questions. |