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. Link to comment https://forums.phpfreaks.com/topic/169175-using-getelementsbyclassname-beginner-question/ 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. Link to comment https://forums.phpfreaks.com/topic/169175-using-getelementsbyclassname-beginner-question/#findComment-892639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.