0
I have seen several examples of how to do this here in the stack, but I don’t know why the answers don’t clarify much, then I’d like to to ask again how could I use JS to get the "tag ID <A>
of the following DIV, REMEMBERING that my code is in the main DIV.
<li id="sem-importancia">
<DIV id="principal">
<a id="um-teste"> </a>
</DIV>
</li>
when I use the following js, it works perfect and caught a tag above...
var item_id = elem.parent('li').attr('id');
SOON what code to use to catch the tag below ? a
< a id="um-teste" > < /a >
thank you!
Are you using jQuery? This does not work in Javascript:
elem.parent('li').attr('id');
Solution with jQuery is one thing, with pure Javascript is another. I saw an answer that you accepted earlier, about getting an element ID, that the answer is wrong if it’s pure JS (If it worked for you, it’s because you used jQuery. When it’s like this, you have to put in the tags that is jQuery). I would suggest to correct that and this one, if you want in jQuery too. Although for these simple things, the ideal is pure JS.– Bacco
If you are in jQuery you have this related question: en.stackoverflow.com/questions/116446/how-to-select-the-sibling elements
– Gabriel Rodrigues
hello Bacchus and Gagriel, good .. as I am new please forgive me these mistakes... I swore that I was soh JS... I have noticed now. that this project I’m working on.. has parts of jquery and parts in JS... I’m trying to learn... I also think the idella is pure JS.. or at least until I learn...
– Roberval Sena 山本