javascript document.getElementsByClassName compatibility with IE

前端 未结 7 663
逝去的感伤
逝去的感伤 2020-11-22 08:44

What is the best method to retrieve an array of elements that have a certain class?

I would use document.getElementsByClassName but IE does not support it.

7条回答
  •  不要未来只要你来
    2020-11-22 09:09

    you may create the function for older browsers

    if (typeof document.getElementsByClassName!='function') {
        document.getElementsByClassName = function() {
            var elms = document.getElementsByTagName('*');
            var ei = new Array();
            for (i=0;i

提交回复
热议问题