Reputation: 219
I just find that document.getElementsByClassName() is not available for IE8. For this reason I want use document.querySelectorAll(), but my real problem is that class name come in a varible, and can't get the result of the function. Like this:
var linea = document.querySelectorAll(revisados[i].value);
My function is triggered by an checkbox by an onchange(value), and when the execution check the parameter value of querySelectorAll fail. I tried:
<input type="checkbox" value="1" onchange="javascript:name(this)" />
The value is a class for many other elements. And the JS:
function name(param){
var className=param.value;
var class2 = "."+class;
var linea = document.querySelectorAll("."+param); //doesn't work
var linea = document.querySelectorAll("."+className); //doesn't work
var linea = document.querySelectorAll("."+className.value); //doesn'twork
var linea = document.querySelectorAll(class2); //doesn'twork
var linea = document.querySelectorAll(String(class)); //doesn't work
}
Please any suggestion. Thanks a lot.
Upvotes: 0
Views: 8143
Reputation: 36703
Use querySelector
function name(param){
var classValue=param.value;
linea = document.querySelector("."+classValue);
console.log(linea.length)
}
Also IE8 does not allow CSS class to begin with a digit.
Upvotes: 1