Difference between .on() and .bind()?

  • .bind() → Older method for event binding (not recommended now).
  • .on() → Modern, more powerful. Can bind multiple events and works with dynamically added elements.

Example:

// Old
$("#btn").bind("click", function(){ alert("Clicked!"); });

// New
$("#btn").on("click", function(){ alert("Clicked!"); });

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *