How to change the CSS with javascript ?

Posted by  Aaron Douglas
 1782  View(s)
Rate this:

I do not know how to access a specific CSS using javascript.

Let us say,

#menu { color: red; }
can be accessed by
document.getElementById('menu').style.color = "blue";
But I want to access
#menu li a { height: 10%; }

How do I access that using document.getElementById() ?

Thanks is advance
  1. Re: How to change the CSS with javascript ?


     your answer is this

    The .getElementById() function is about getting an element by a unique "id" string. If you need to get elements otherwise, there are other APIs to use: .getElementsByTagName(), .getElementsByClass(), .querySelectorAll(), etc. Browser support varies, and even .getElementById() is different between IE and other browsers.