![]() |
Hide class
Hello :)
My assignment is to find all <p> and hide the ones that are <p class="show"> using a For Loop. "show" is supposed to be hidden when loading the page, because im gonna do a < a > that is gonna show them. This is what i have done, and it doesnt work. Did i do something wrong or am i way off here ? windows.onload = prepareShow; function prepareShow(){ var fan = document.getElementsByClassName("show"); for (var i = 0; i < fan.length; i++){ if (fan[i].getAttribute("class")=="show"){ fan[i].style.display="none";} } } |
Can be done a few ways but :
Code:
<html> |
You can make the code a lot shorter than that:
Code:
function LetsSee() |
Quote:
You can make the code a lot shorter than that, (and re-usable): Code:
function LetsSee(c,s,r){r=(r||document).getElementsByClassName(c);usage: LetsSee(classToHit , displayStyleToSet, opt_elmRoot ); ex (do what the previous codes do): Code:
LetsSee("show","block"); |
Quote:
Code:
function LetsSee(c,s,r){x=(r||document).getElementsByClassName(c); |
| All times are GMT +1. The time now is 07:41 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.