Javascript, getting lots of elements and setting them to display none
i wish to grab a load of elements, check if their id contains 'other' or 'Other' and for those, set the display to none. This is what i have:
function Hide(div){
var list;
var i;
list = document.getElementById(div).getElementsByTagName("input")
for(i=0; i<list.length;i++){
if(lis开发者_运维知识库t[i].id.toString().indexOf("Other") != -1 || list[i].id.toString().indexOf("other") != -1){
list[i].id.setAttribute("Style.display","none");
}
}
}
but .setAttribute... doesnt work and nor did .Style.display = "none"
Adjust the style property of the element not the string containing the id!
list[i].style.display
You can't use style.display
, because 'display
' is a property of the style
Object.
You should use:
list[i].style.display = 'none'
Try list[i].style.display
, lower case, set attribute to object itselft
精彩评论