How to Get Element By Class in JavaScript?

前端 未结 11 2493
南旧
南旧 2020-11-22 01:48

I want to replace the contents within a html element so I\'m using the following function for that:

function ReplaceContentInContainer(id,content) {
   var c         


        
11条回答
  •  孤城傲影
    2020-11-22 02:16

    I assume this was not a valid option when this was originally asked, but you can now use document.getElementsByClassName('');. For example:

    var elements = document.getElementsByClassName(names); // or:
    var elements = rootElement.getElementsByClassName(names);
    

    See the MDN documentation for more.

提交回复
热议问题