Today, when developing a project, you need to bind a click event to a dynamically generated element of JS, but before the page loads, the element does not exist, it cannot be fetched, and then an event is added to it. Review the jquery API discovery to use the On () event (note: The new version of jquery has removed live (), is now on ()), binds events to dynamically produced elements, and then triggers the event execution. For example, one of the following:
Let's say we're going to add the span binding click event to the div dynamically to produce the following result
x//The procedure isas follows:("#choose_result"). On ("click", "Span", function () {
Do something here
});
To actively trigger a span's Click event
(". Close"). Trigger ("click");
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How to bind events with JS for dynamically generated elements