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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:47:27+00:00 2026-06-07T06:47:27+00:00

Given the following code, why does the selector property work in the first instance

  • 0

Given the following code, why does the selector property work in the first instance but not the second? Aren’t they both jQuery objects?

<span class='tst'>span</span>​

var tst = $('.tst');
console.log(tst.selector); 
// prints '.tst'

$('.tst').each(function() { console.log(this.selector);});
// prints undefined​​​​​​​
  • 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-07T06:47:28+00:00Added an answer on June 7, 2026 at 6:47 am

    this, in the context of the .each() loop, is not a jQuery object, so the selector property is undefined.

    You need to make it a jQuery object first: $(this).selector

    However, it should be noted that the selector property will return an empty string while inside the .each() loop.

    Edit

    If you absolutely need the selector property within the .each(), one option would be to cache your selector:

    var cached = $('.tst');
    
    cached.each(function() { 
        console.log(cached.selector); // Will display ".tst"
    });
    

    ​

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

Sidebar

Related Questions

Following code does NOT work, but it expresses well what I wish to do.
Given the following property definition: @property (nonatomic,retain) MyObject* foo; does the following code cause
Given the following code (copied from the attoparsec library) what does the inline pragma
The following code does not give a warning with g++ 4.1.1 and -Wall .
Given the following code: string istanbul = 523; Convert.ToInt32(istanbul.ToString(00)); what does it return?
I am trying to figure this out, given the following code, does the Refresh()
Not sure if this has been asked, but here it goes, given the following
Given the following code: Class User{ Task m_Task; public function getTask(Do work) { return
Given the following code @interface MyClass { SomeObject* o; } @property (nonatomic, retain) SomeObject*
Given the following code, how does EF/DbContext knows about the change made to 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.