/    Sign up×
Community /Pin to ProfileBookmark

div visibility

Hi.
I’m sorry if this question is too amateur.
I’m just appying some inherited code and I’m not a JS professional.
So, I ask for your help.

I’m doing a top menu that show and hides several div:

[CODE]<script type=”text/javascript” language=”JavaScript”><!–

function HideAllShowOne(d) {
// Between the quotation marks, list the id values of each div.

var IDvaluesOfEachDiv = “id1 id2 id3 id4 id5 id6″;

//————————————————————-
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/[,s”‘]/g,” “);
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/^s*/,””);
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/s*$/,””);
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/ +/g,” “);
var IDlist = IDvaluesOfEachDiv.split(” “);
for(var i=0; i<IDlist.length; i++) { HideContent(IDlist[i]); }
ShowContent(d);
}

function HideContent(d) {
document.getElementById(d).style.display = “none”;
}
function ShowContent(d) {
document.getElementById(d).style.display = “block”;
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == “none”) { document.getElementById(d).style.display = “block”; }
else { document.getElementById(d).style.display = “none”; }
}
//–></script>[/CODE]

When the page load, all div are hidden with a “display none” css line, and there is a background image.

Can I show the first div when the page loads and hide it when someone clicks on the menu to view the other divs?
If I change the div visibility on the css, it remains always visible.
I believe that some modification on the script could do that, but I don’t know how to do it.

Thank you for your help

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeMay 19.2011 — This is kind of 'hackish', but..

You could take the ID of that first div and use JS to set the display to be "" on page load.

function setFirst() {

firstDiv = document.getElementById("divName");

firstDiv.style.display = "";

}

window.onload = setFirst; // NOTICE - no parenthesis when calling this with window.onload
Copy linkTweet thisAlerts:
@nautiliaauthorMay 20.2011 — WolfShade, thank you for your answer. It works!

I added 'block' to firstDiv.style.display = ""; (firstDiv.style.display = "block"? and it's working the way I wanted.

Thanks for your help!
×

Success!

Help @nautilia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...