How to getElementByClass instead of GetElementById with JavaScript?

前端 未结 7 777
孤街浪徒
孤街浪徒 2020-11-22 09:33

I\'m trying to toggle the visibility of certain DIV elements on a website depending on the class of each DIV. I\'m using a basic JavaScript snippet to toggle them. The probl

7条回答
  •  迷失自我
    2020-11-22 09:54

    My solution:

    First create "

    Then, I create a function in JavaScript like this:

    document.getElementById('YourID').innerHTML = '.YourClass {background-color:blue}'
    

    Worked like a charm for me.

提交回复
热议问题