Javascript change Div style

后端 未结 7 1701
轻奢々
轻奢々 2021-01-03 18:30

I want that part 1 onclick div style changes and part 2 again on click it comes back to normal. I tried doing so but I failed to achieve the

7条回答
  •  醉梦人生
    2021-01-03 18:54

    Better change the class of the element (.regular is black, .alert is red):

    function abc(){
      var myDiv = document.getElementById("test");
      if (myDiv.className == 'alert') {
        myDiv.className = 'regular';
      } else {
        myDiv.className = 'alert';
      }
    }
    

提交回复
热议问题