IE 11: Object doesn't support property or method 'getElementsByClassName'

杀马特。学长 韩版系。学妹 提交于 2020-05-29 10:32:10

问题


This is not a duplicate. Previous questions relate to IE8. This is occurring in IE11.

I have no problems running this in Chrome or Firefox, but my code must function in IE11 and I am receiving the following error:

Object doesn't support property or method 'getElementsByClassName'

function showNext(a) {
    var questions = document.getElementsByClassName("questionholder");
    showRequired.style.display = "none";

    for (var i = 0; i < questions.length; i++) {
        questions[i].style.display = "none";
    }

    var nextQuestion = document.getElementById("question" + a);

    if (nextQuestion !== null) {
        nextQuestion.style.display = "inline-block";
    }
}

The code is supposed to be looking here:

<form id="TheForm" style="display:block;">
    <div class="questionholder" id="question0" style="display:block">
        <a class="text2button" onclick="showNext(1)">Start</a>
    </div>
    <div class="questionholder" id="question1" style="display:block">
        <a class="text2button" onclick="showNext(2)">Q1</a>
    </div>
    <div class="questionholder" id="question2" style="display:block">
        <a class="text2button" onclick="showNext(3)">Q2</a>
    </div>
</form>

The code above will hide all divs and then show the div that matches the id "question"+a as determined by the button clicked.

What can I do to resolve the above error?


回答1:


The fix is as follows:

<meta http-equiv="X-UA-Compatible" content="IE=11" />


来源:https://stackoverflow.com/questions/56265315/ie-11-object-doesnt-support-property-or-method-getelementsbyclassname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!