I have an html element that I want to hide from view, but I can't access that element by an ID because it has no ID and I can't assign an ID to it. It has a class assigned to it though. Is there any possible way to hide this element from view without having it's id?
+1
A:
There's getElementsByClassName in some browsers, but it's not as widely supported as getElementById. Note that it yields an array of elements, instead of just a single element, as several elements can have the same class.
If you can assign an ID to a parent you might be able to access it in some other way:
document.getElementById('parent').getElementsByTagName('div')[3] // or whatever
David Hedlund
2010-08-24 20:36:52
okay... I can access it through a parent id. How would I go about hiding it from view after I've accessed it?
lewisqic
2010-08-24 20:41:11
nevermind, I figured it out...var elements = document.getElementById('home_poll').getElementsByTagName('a'); elements[2].style.display = "none";
lewisqic
2010-08-24 20:44:04