2

Let's say you have the following div:

<div id="someId">
</div>

You get the div by using:

var element = $('#someId');

How can you turn element into '#someId'? I would also like an answer that work for more complex cases where there are multiple classes and ids.

I want to do this, because I would like to append that string into another selector to target very specific DOM elements.

henry
  • 119
  • 1
  • 10
  • 3
    You mean [get the selector from a jQuery object](http://stackoverflow.com/questions/2420970/how-can-i-get-selector-from-jquery-object)? Are you sure you need it? What exactly are you trying to do? – Stryner Feb 24 '16 at 22:32
  • It's useful when repeating divs all have the same class names. – henry Feb 24 '16 at 23:05
  • You can use [`.find`](https://api.jquery.com/find/) to search the descendants. It even has a `.find($element)` override. I don't understand the use case that requires it. – Stryner Feb 24 '16 at 23:11
  • I want to do the opposite. – henry Feb 24 '16 at 23:27

0 Answers0