tags:

views:

25

answers:

1

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
okay... I can access it through a parent id. How would I go about hiding it from view after I've accessed it?
lewisqic
nevermind, I figured it out...var elements = document.getElementById('home_poll').getElementsByTagName('a'); elements[2].style.display = "none";
lewisqic