jQuery Event Delegation with on()

Attach listeners to dynamic elements added to the DOM after page load.

Direct event listeners ($(".btn").click(...)) do not bind to elements created dynamically later. Event delegation via $(parent).on("click", selector, handler) handles future elements seamlessly.

Key Takeaways: jQuery Event Delegation with on()

Mastering jQuery Event Delegation with on() helps you write clean and reliable jQuery code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

jQuery Event Delegation with on() Code Example

jQuery
$(document).on("click", ".dynamic-item", function() {
  console.log("Clicked dynamic element:", $(this).text());
});
Output
Listens for clicks on dynamic elements injected later
Free sign-in required · Google login available
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services