0

I'm trying to change the css rules on a class called active which have static css already but i would like to alter a rule in it to make an div animate slide. i don´t know how to target a class instead of an element with the name of the class.

Javascript

var active = document.getElementsByClassName('active');
active.style.color = 'red';

I´ve tried both these methods but none seems to work.

var i = 0;
    while(i < divs.length) {
        if(divs[i].className == "active") {
            var b = 0;
            for (var a = 0; a < 10; a++){
                divs[i].style.left = b+'em';
                b += 6;

            }
        }
        i++;
    }

I´t wont add left to the css rule nor color.

CSS

.active{
position:absolute;
left:-60em;

Jquery is not an option in this case.

2
  • can you add a fiddle with your necessary code, there could be multiple problems in the code? Commented Aug 29, 2014 at 11:32
  • I want to grab the class name "active" and change the left rule to 60em with Javascript. Commented Aug 29, 2014 at 11:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.