1
Hello,
I’m trying to make a function that by clicking on an element I can either catch the tree(all parents) of the element (up to the body or a specific tag), or take something similar to the "Copy -> Copy Selector" of Devtools.
For example when I click on b
return me something like div > nav > h3 > b
.
Clicking on the label
return div > label
.
Clicking on the h3
return div > nav > h3
.
You can include the body if you want... If you need to insert an id in an element to know where to stop is a viable solution too.
Thank you in advance!
Edit
Improving doubt...
Let’s assume I have an HTML structure inside a div.
For example:
<div id="stack-ex">
<div>
<nav>
<label>Teste</label>
</nav>
<label>Texto 2</label>
</div>
</div>
I need to list the content of #stack-ex
sort of like this:
- div
- Nav
- label
- label
- Nav
Then the structure of <li>
is a reference to the content of #stack-ex
, I would later need along with the list to have the selector
the element the list item references. Because then I’ll put something like a button to change color, or other cases.
So when I click I would need to take the parent
'cause then I’d just use $(aqui)
being aqui = #stack-ex > div > nav > label
.
The click was just something to illustrate for you to help me with a practical example, I’m not necessarily going to click and call the function.
Renan, you only need the name of the tags ? or the HTML object itself?
– Leonardo Bonetti
Basically the same string.
– Renan Prado
I really couldn’t quite understand the purpose. I even apologized, but I didn’t really understand. I think it would be interesting to talk in a chat so you can explain this and what the goal is, because I’m finding it strange to take the whole tree of the element. I believe that I should have a better and simpler solution. I stand by.
– Sam
Hello, we can chat yes in a chat, how can we do this?
– Renan Prado