I have two elements and would like to select the parent element using only Javascript, does anyone know of any way?
<tr>
<td id="filho"><td>
</tr>
I have two elements and would like to select the parent element using only Javascript, does anyone know of any way?
<tr>
<td id="filho"><td>
</tr>
Use parentNode
:
Node.parentNode
var filho = document.getElementById("filho");
var pai = filho.parentNode;
console.log(pai);
<div id="pai">
Sou Pai
<div id="filho">
Sou filho do meu pai :D
</div>
</div>
Use the parentNode
property
Ex:
document.getElementById('filho').parentNode