Reputation: 135
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
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
Reputation: 1267
getElementById is a function of document.
var listParentNode = document.getElementById("list2").parentNode;
Upvotes: 1