$(selector).on(event, childSelector, function)
<div id="parent">
<div class="child"> child 1</div>
</div>
"#parent"
As stated above, you can alternatively select the body tag for your parent.
"body"
Your child selector for the dynamic elements will use the class "child".
".child"
$("#parent").on("click", ".child", function (e) { //do something });
<div id="parent">
<div class="child">child 1</div>
<div class="child">child 2 added dynamically</div>
<div class="child">child 3 added dynamically</div>
</div>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)