0

I am no sure whether I made the question title right, but I want to ask a question below

<div title="A"></div>

var a = $([title=A]);

//if I only know a, how can I get what is referring here made a, 
//or command I use can get out put of the referring. 
//This case the out put will be '[title=A]'

I am not asking for a.attr('title');

4
  • 1
    I think you need to re-word this question. Commented Jan 31, 2013 at 19:19
  • Your wording is very confusing. Do you mean that you want the selector that was used to retrieve the value that was assigned by jquery to a? Commented Jan 31, 2013 at 19:20
  • Thank you, do you mean the question title does not match the actual question? Commented Jan 31, 2013 at 19:20
  • yes, I think I want to know the selector... Commented Jan 31, 2013 at 19:23

2 Answers 2

2

You can use selector property in jQuery object to get the selector that was used.

var a = $('[title=A]');
alert(a.selector);  //will alert [title=A]

DEMO: http://jsfiddle.net/Zz4MW/

Note: Use selector property with caution as it is for internal usage. See Why does the .selector property in jQuery not store a valid selector value? for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

That is not reliable--see this thread.
1
var a = $('[title=A]');
console.log(a.get()[0]);

jsFiddle example

See http://api.jquery.com/get/ for more info on .get()

1 Comment

a.get()[0] == a.get(0) == a[0].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.