Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click on html element except a dynamically created elements?

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?

like image 631
Nighina t t Avatar asked Nov 24 '25 20:11

Nighina t t


1 Answers

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();})

like image 194
Prashant Shirke Avatar answered Nov 27 '25 10:11

Prashant Shirke