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');

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Micah
  • 4,254
  • 8
  • 30
  • 38

2 Answers2

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.

Community
  • 1
  • 1
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
  • 2
    That is not reliable--see [this thread](http://stackoverflow.com/questions/12426622/why-does-the-selector-property-in-jquery-not-store-a-valid-selector-value). – Ted Hopp Jan 31 '13 at 19:24
1
var a = $('[title=A]');
console.log(a.get()[0]);

jsFiddle example

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

j08691
  • 204,283
  • 31
  • 260
  • 272