apply CSS style to particular elements dynamically

前端 未结 5 2073
我在风中等你
我在风中等你 2021-01-15 19:56

I have a div with paragraphs inside:

...

...

I want dynamically to apply

5条回答
  •  Happy的楠姐
    2021-01-15 20:47

    Changing the css dynamically would be as simple as changing the top level class name for example

    ...

    ...

    Test

    .class1 {
     background-color:#F00;
    }
    
    .class1 p {
        color:#00F;
    }
    
    .class2 {
        background-color:#00F;
    }
    
    .class2 p {
     color:#F00;
    }​
    

    then the jquery would be

    $(document).ready(function() {
        $('#test').click(function() {
            $('#toggleme').toggleClass('class1');
            $('#toggleme').toggleClass('class2');
        });
    });​
    

    Everything below the class will change to its new style :)

    fiddle

提交回复
热议问题