How to Get Element By Class in JavaScript?

前端 未结 11 2362
南旧
南旧 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:26

    I think something like:

    function ReplaceContentInContainer(klass,content) {
    var elems = document.getElementsByTagName('*');
    for (i in elems){
        if(elems[i].getAttribute('class') == klass || elems[i].getAttribute('className') == klass){
            elems[i].innerHTML = content;
        }
    }
    }
    

    would work

提交回复
热议问题