Why not use jquery to get dynamically generated elements through events?

$("body"). On ("click", "selector", function () {})
this is the method that is called after the dynamically generated element is clicked.
I now dynamically generate input and then immediately get this dynamically generated element without triggering
through a click event. How can I get it?

Apr.26,2021

first heard that getting elements depends on events.
jquery is good at element filtering, isn't it?
you add a little filter flag to the newly generated input to filter directly, or you can directly createElement and get


right away.

when defining a variable globally, such as var countCreate = 0 , you can add some class or id, to dynamically generated elements, such as

.
var countCreate = 0
var set = document.createElement("li");
set.setAttribute('id', 'x:' + countCreate.toString());

so that each new element can be found independently through id.
even, this set is a new element, and you can do whatever you want.


event delegation

Menu