Detect multiple classnames without jquery

czmuiqrman3863

New Member
Learning DOM0 javascript and the prof has thrown a curveball. He writes dozens of paragraphs with class names: sports, life, books, comedy and then this:\[code\]<p class="sports books comedy"> I found this book: http://www.amazon.com/Teed-Off-Laughs-Greens-Sports/dp/0233995005/ref=sr_1_1?ie=UTF8&s=books&qid=1277749796&sr=1-1 You don't have to be good to play, but a low level of self-esteem is helpful! Humorous collection of colour photographs and hilarious text reduces our heroes of the golf course to mere mortals. No golfing disaster is left secret and the 80 photographs only go to prove the fallibility of international stars.</p>\[/code\]Have to style it without using Jquery, my thought was this: \[code\]window.onload=function(){ var elements = document.getElementsByTagName('*'); for (var i=0; i<elements.length; i++) { if (elements.className == 'sports') { elements.style.border="2px solid green"; } else if (elements.className == 'life') { elements.style.color="red"; } else if (elements.className=="books") { elements.style.textAlign="right"; } else if (elements.className=="comedy") { elements.style.fontSize="200%"; } }}\[/code\]Which works for everything except the multiple classname. Trying to find a way around it.
 
Back
Top