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
  • 63,812
  • 29
  • 142
  • 238
Micah
  • 3,911
  • 7
  • 29
  • 33

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
  • 78,145
  • 14
  • 119
  • 133
  • 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
  • 197,815
  • 30
  • 248
  • 265