Reputation: 140
I need to trigger click in an html page except a div.but that div is created dynamically after page load.I have tried following code.
$('html').click(function(e) {
if(!$(e.target).hasClass('flyoutdiv') ){
}
});
It is working only for element that is not created dynamically. "flyoutdiv" is created dynamically after page load.I need to trigger click in the entire page except that element.is there any solution?
Upvotes: 3
Views: 69
Reputation: 394
After you created flyoutdiv, bind a event listener to him. After creation of div add $('.flyoutdiv').click(function(){//your code here});
It is much better than searching for target on every click.
Upvotes: 1
Reputation: 1423
You need to attach click event to flyoutdiv
div like following.
$(".flyoutdiv").on('click',function(e){e.stopPropagation();})
to handle dynamic flyoutdiv
you can use the code like following.
$("body").on('click',".flyoutdiv",function(e){e.stopPropagation();})
Upvotes: 2