Home > DeveloperSection > Forums > How to change the CSS with javascript ?
Aaron Douglas
Aaron Douglas

Total Post:20

Posted on    August-19-2013 12:59 AM

 JavaScript JavaScript 

 1 Reply(s)
 1117  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

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    August-19-2013 8:28 AM

 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.

Don't want to miss updates? Please click the below button!

Follow MindStick