I want to check if event target is descendant of specific wrapper.
Should i use has() function or parents()?
if($('.wrapper').has(e.target).length){
//do something
}
vs
if ($(event.target).parents('.wrapper').length){
//do something
}
It's up to you. Use whatever you find more readable or convenient.
Method three would be proper delegation :
$(document).on("click", ".wrapper *", function (e) {
// whatever
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.