$("button").on("click", function() {
$("ul").append($("<li></li>").text("good"));
});
$("ul").on("click", "li", function() {
$(this).remove();
});
$("ul").on("mouseenter", "li", function() {
$(this).css("color", "yellow");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<button>click me</button>
<li>good</li>
</ul>
Can we use objects in on()
to create multiple events to elements that are yet to be created?