Gleasonator Posted August 7, 2009 Share Posted August 7, 2009 Hi, I'm very new to JavaScript and have found myself needing to select every element by a classname and apply a style to it. Something like: textholder = document.getElementsByClass("redtext"); textholder.style.color = "red"; Obviously the above does not work - my question is, how can I get this to work? I'm also aware that the above can be done easily with CSS, but it's the concept I'm trying to grasp here and not the exact example. Thanks. Quote Link to comment Share on other sites More sharing options...
haku Posted August 7, 2009 Share Posted August 7, 2009 There is a function - getElementsByClassName, but unfortunately, the bestest browser in the whole widest world doesn't support it - yep, IE. Here is a little write up on the matter: http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/ Basically, it's not easy to target all elements with a specific class name across browsers without using a library like jquery. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.