Anna Bannanna
Anna Bannanna

Reputation: 135

Javascript DOM styling

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

Upvotes: 0

Views: 39

Answers (2)

Chen Don
Chen Don

Reputation: 16

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

Upvotes: 0

Mengo
Mengo

Reputation: 1267

getElementById is a function of document.

var listParentNode = document.getElementById("list2").parentNode;

Upvotes: 1

Related Questions