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

  • SEARCH
  • Home
  • 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 8555143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:03:18+00:00 2026-06-11T15:03:18+00:00

Why is it important to use $(this) instead of re-selecting the class? I am

  • 0

Why is it important to use $(this) instead of re-selecting the class?

I am using a lot of animate and css editing in my code, and I know I can simplify it by using $(this).

  • 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-06-11T15:03:19+00:00Added an answer on June 11, 2026 at 3:03 pm

    When you perform an DOM query through jQuery like $('class-name') it actively searched the DOM for that element and returns that element with all the jQuery prototype methods attached.

    When you’re within the jQuery chain or event you don’t have to rerun the DOM query you can use the context $(this). Like so:

    $('.class-name').on('click', function(evt) {
        $(this).hide(); // does not run a DOM query
        $('.class-name').hide() // runs a DOM query
    }); 
    

    $(this) will hold the element that you originally requested. It will attach all the jQuery prototype methods again, but will not have to search the DOM again.

    Some more information:

    Web Performance with jQuery selectors

    Quote from a web blog that doesn’t exist anymore but I’ll leave it in here for history sake:

    In my opinion, one of the best jQuery performance tips is to minimize your use of jQuery. That is, find a balance between using jQuery and plain ol’ JavaScript, and a good place to start is with ‘this‘. Many developers use $(this) exclusively as their hammer inside callbacks and forget about this, but the difference is distinct:

    When inside a jQuery method’s anonymous callback function, this is a
    reference to the current DOM element. $(this) turns this into a jQuery
    object and exposes jQuery’s methods. A jQuery object is nothing more
    than a beefed-up array of DOM elements.

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

Sidebar

Related Questions

Why I ask this question: I know there have been a lot of questions
Edit: based on a Ulf Rompe's comment, it is important you use 1 instead
I am importing Tables from a Oracle DataBase, using a VB.NET dataAdapter. I use
Important : Please see this very much related question: Return multiple values in C++
An important property of really SOLID code is the fact that constructor calls do
Some important part of my code is running in viewDidLoad and I was wondering
Screenshot Important Note : This application does not support Internet Explorer. I will be
There is very important shortcut for "Basic Code Completion" in IntelliJ IDE which assumed
Is it really important to know algorithms to build mobile applications? I have strong
I know this is more heavy question, but I think its interesting too. It

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.