Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:52:52+00:00 2026-05-27T07:52:52+00:00

Assuming I just want to attach a simple click handler to an element, I’ve

  • 0

Assuming I just want to attach a simple click handler to an element, I’ve always done this:

$("#mydiv").click(function() { ... });

Looking at the JQuery docs, it seems that .on() is the “recommended” way to attach event handlers and replaces .bind(), .delegate() and .live():

As of jQuery 1.7, the .on() method provides all functionality required
for attaching event handlers. For help in converting from older jQuery
event methods, see .bind(), .delegate(), and .live().

And in the docs for .click() it says:

This method is a shortcut for .bind(‘click’, handler) in the first two variations, and .trigger(‘click’) in the third.

So this implies that .click() is using .bind() which will be deprecated and replaced by .on(), right? Or is the implication that .click() will stick around, but it will at some point become a shortcut for .on("click")?

Basically, my question is this… When writing JQuery code today, should I use:

Variant 1: $("#mydiv").click(function() { ... });

or:

Variant 2: $("#mydiv").on("click", function() { ... });

?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:52:53+00:00Added an answer on May 27, 2026 at 7:52 am

    Personally I would use on() for all event bindings from jQuery 1.7+.

    It means there’s no ambiguity between elements which are added dynamically and those available on page load.

    Also, as you state, click() (and other event shortcuts) are converted to on("event", function() { ... }); by jQuery anyway, so it saves a step in the process – not that this makes a noticeable difference of course.

    And finally, on("click") reads better in my opinion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just created an acc on SO to ask this :) Assuming this simplified example:
I could resolve this problem just now but assuming others might have the same
I have run across many cases where I just want a simple database that
Just want to make sure I am not assuming something foolish here, when implementing
I just want to ask is there a simple way in C++ to make
Is there a difference between just saying throw; and throw ex; assuming ex is
Assuming I'm trying to automate the installation of something on windows and I want
I just want to know for what java.util.Collections.checkedList() is actually used. I have some
Assuming a collection like this: People { name: John Doe, email: John Doe <john@doe.com>,
I just want to know if there's a better solution to parse a number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.