javascriptdomstylesparent-node

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


Solution

  • getElementById is a function of document.

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