0

I want to reach the parentnode of my list (with an id selector)and style it adding a background color using plain javascript. This is my code, but doesn't work.

    var listParentNode;
    listParentNode = getElementById("list2").parentNode;
    listParentNode.style.backgroundColor = "#deff00"; 

Any ideas why it doesn't work and how I can fix it? Thanks

Anna Bannanna
  • 135
  • 3
  • 10

2 Answers2

1

getElementById is a function of document.

var listParentNode = document.getElementById("list2").parentNode;
Mengo
  • 1,177
  • 1
  • 10
  • 25
0

var listParentNode;
listParentNode = document.getElementById("list2").parentNode;
listParentNode.style.backgroundColor = "#deff00"; 
<div>parent div
  <div id="list2">inside div</div>
</div>

you should use document.getElementById

Chen Don
  • 16
  • 3