The event monitoring of js is different from that of css. As long as the style of css is set, whether it is existing or newly added, it will have the same performance. But event listening is not the case. You must bind events to each element individually.
A common example is when processing tables. There is a delete button at the end of each line. Click this to delete this line.
This line originally had |
Delete |
;/button>
Usually, I would bind like this
Solution No. 0 - onclick method
Note that the deltr function at this time must be a global function and must be placed outside jQuery(function($) {}). If placed inside, it becomes a local function, and onclick in html cannot be called!
and then bind them again when newly added elements are added.
Then use the event.target object to determine whether this event was triggered by the object we are looking for.
Usually you can use some DOM attributes, such as event.target.className, event.target.tagName, etc. to judge.