Change CSS properties on click

后端 未结 8 2344
情话喂你
情话喂你 2020-11-29 22:53

I am trying to change the CSS of one element on click of another element. I\'ve searched a lot but nothing works perfectly. Currently I am using the below code, but it doesn

8条回答
  •  情歌与酒
    2020-11-29 23:42

    Try this:

    CSS

    .style1{
        background-color:red;
        color:white;
        font-size:44px;
    }
    

    HTML

    hello world!

    Javascript

    function myFunction()
    {
        document.getElementById('foo').setAttribute("class", "style1");
    }
    

提交回复
热议问题