Select parent element with javascript (without Jquery) [duplicate]

0

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>
    
asked by anonymous 06.10.2017 / 21:36

2 answers

6

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>
    
06.10.2017 / 21:39
1

Use the parentNode property

Ex:

document.getElementById('filho').parentNode
    
06.10.2017 / 21:39