HOW TO CHANGE THE CSS WITH JAVASCRIPT ?

Aaron Douglas

Total Post:20

Points:140
Posted by  Aaron Douglas
 1174  View(s)
Ratings:
Rate this:
Hi!

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. shreesh chandra shukla

    Post:105

    Points:735
    Re: How to change the CSS with javascript ?

    Hi!

     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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!