问题
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
回答1:
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";
}
}
For multiple elements: 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';
}
}
}
来源:https://stackoverflow.com/questions/22882305/get-element-by-classname-for-ie11