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 6785233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:06:07+00:00 2026-05-26T17:06:07+00:00

This is a simple question regarding $(this) and how it is defined and redefined

  • 0

This is a simple question regarding $(this) and how it is defined and redefined in a chunk of code.

$('input').live('click', function() {
    $(this).addClass('active');
    if( question.find('.false').is(':visible') ){
      question.find('.false').hide("blind",{},350);  
    }
})

$(this) is unambiguously the input on the second line. Now, when we start the if statement, I have a new point of interest: question.find('.false'). If $(this) does not change to the new definition, is there an easier way to refer to question.find('.false')?

A follow-up for clarity

If I want to refer to question.find('.false') a few times in a longer version of the loop above, what’s the best way to refer to it?

  1. Define a new variable before the loop:

    var qfalse = question.find('.false')
    if( qfalse...){...qfalse this, qfalse that...
    
  2. Something else?

  • 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-26T17:06:08+00:00Added an answer on May 26, 2026 at 5:06 pm

    this will keep it’s value until some new context redefines this (like in a .each() callback). It keeps it’s value everywhere in your function.

    You can do what you were trying to do a bit simpler. Rather than using the if test, just require the selector to be visible and only operate on the visible ones.

    $('input').live('click', function() {
        $(this).addClass('active');
        question.find('.false:visible').hide("blind",{},350);
    })
    

    In practice, you can call hide on all of them and the ones that are already hidden will be just ignored by the .hide() method.

    $('input').live('click', function() {
        $(this).addClass('active');
        question.find('.false').hide("blind",{},350);
    })
    

    If you want to use the same jQuery selector object in multiple places in your function and you can’t just chain multiple methods together, then you would just use a local variable to assign the selector to and then use that variable:

    $('input').live('click', function() {
        $(this).addClass('active');
        var $falseQuestions = question.find('.false');
        // do whatever other operations you want on/with $falseQuestions here
        $falseQuestions.hide("blind",{},350);
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday, I asked this question regarding best practices for a simple information retrieval system
I searched google but couldn't find an answer to this rather simple question. I
Anybody? There is another question regarding this but the only answers were to code
(code below regarding my question) Per this stack overflow question I used Pegolon's approach
I have this (simple) question regarding an array. I am trying to get the
Okay, this is following on from my previous question reguarding performing a simple ajax
This is just a simple question. I've been reading the source of something which
This seems to be an embarrassingly simple question, but, after a day of reading
I searched and searched for an answer for this seemingly simple question in Commerce
This is a simple question I think. I am trying to search for the

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.