-4

Is it possible to get an id that is under an other id like this:

<p id="moe1" onclick="moe()">Mamamia</p>
<p id="socket1">Pizzaria</p>

So if i know that my id is "moe1", how can i find what is the id under "moe1"?

user2959870
  • 80
  • 6
  • 25

2 Answers2

-1

you could use CSS adjacent sibling selector

document.querySelector("#moe1 + p").id

or for all elements not only p tags

 document.querySelector("#moe1 + *").id
Vladu Ionut
  • 8,075
  • 1
  • 19
  • 30
-1

This line of code worked for me:

document.getElementById('moe1').nextSibling;    
user2959870
  • 80
  • 6
  • 25