How to getElementByClass instead of GetElementById with JavaScript?

前端 未结 7 692
孤街浪徒
孤街浪徒 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 10:02

    Use it to access class in Javascript.

    <script type="text/javascript">
    var var_name = document.getElementsByClassName("class_name")[0];
    </script>
    
    0 讨论(0)
提交回复
热议问题