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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:01:35+00:00 2026-06-06T08:01:35+00:00

If an element doesn’t exist, how do I get a string of the selector

  • 0

If an element doesn’t exist, how do I get a string of the selector that was searched?

For example:

$( 'parent child.class' ).plugin( )

In my plugin, I want to get the string "parent child.class", but $( 'parent child.class' ) doesn’t exist.

I’m going to start digging through the jQuery source code, but I figured I’d ask in case someone with more intimate knowledge knows 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-06T08:01:36+00:00Added an answer on June 6, 2026 at 8:01 am

    You can’t.

    jQuery objects have a .selector property, which you could use within your plugin (though it seems to be intended for use interally with jQuery), but – and it’s a big but – not all jQuery objects are created with a selector string. Consider this example use of .yourPlugin():

    $('div.someClass').add(document.getElementById("test"))
                      .add("<div>Hello</div>")
                      .filter(function() {
                          return $(this).attr("data-test") == "blah";
                      })
                      .parents()
                      .yourPlugin();
    

    It doesn’t make sense to be thinking about what selector resulted in the jQuery object eventually passed to .yourPlugin(), regardless of whether it contains any elements.

    (I suppose if you know your plugin will only ever be used by you and you’ll only ever pass it jQuery objects created with a selector then you could use this.selector within your plugin…)

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

Sidebar

Related Questions

I want to write a selector that targets the first element that doesn't have
in jquery when I use element that doesn't exist what happens? Consider: $('<tmp/>').html(some_html_string).text() where
Which is better way to use jQuery() ? I've heard that jQuery(element) doesn't ruin
why doesn't the element get swapped public static void SwapArray(int[,] arr) { for (int
I want to control does an element exist in document with its ID, when
I want to set the value/children of an element that may or may not
I make an element in jQuery plugin: this.addButton = $(<a>, { text: ADD, class:
How can I detect when an element doesn't exist in my table? I need
The PageContent element implements IAddChild but doesn't implements IAddChild methods so I can't call
I tried positioning a div element using margin-bottom. For some reason the margin-bottom doesn't

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.