简体   繁体   中英

Adding event listener for each new element added on body

I want to do a function like Draggable from interact.js . This function adds events to multiple elements, depending of the class name, ID or tag name I choose. When a new element is added on body, it gets an event from this function from interact.js (that maybe like click , mousedown , mousemove , mouseup ). I don't know if my way is good to do:

  • add a onchange event to the body to check if a element was added (by the innerHTML)

Is there a better way to do this?

Maybe this should help Most efficient method of detecting/monitoring DOM changes?

But everyone here appreciates a code snippet to see where you're stuck. please post it

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM