0

I've an issue with queryselectorall and IE11. It works on IE10 and firefox but with last cheet Do you have a solution for having an element by his classname?

if(document.querySelectorAll(".classname"))
{
    alert('ici');
    document.querySelectorAll(".classname").style.display = "none";
}

The alert and display none is working on everything except Internet Explorer 11

thanks

4

1 回答 1

0

http://jsfiddle.net/r3XCd/12/

if (typeof document.querySelectorAll !== undefined) {
    if (document.querySelectorAll(".classname").length > 0) {
      var element = document.querySelectorAll(".classname");
      element[0].style.display="none";
    }
}

对于多个元素:http: //jsfiddle.net/r3XCd/19/

if (typeof document.querySelectorAll !== undefined) {
    if (document.querySelectorAll(".classname").length > 0) {
      var elements = document.querySelectorAll(".classname");
      for (var i=0;i<elements.length;i++) {
        elements[i].style.backgroundColor ='red';
       }
    }
}
于 2014-04-05T15:09:36.890 回答