/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Assignment question

I don’t know if this is a CSS or JS question, so sorry if I post incorrectly.

If I create a CSS rule as:

[code=php]
<style type=”text/css”>
div.grp { display:none; }
</style>
[/code]

and then later initialize a section as:

[code=php]
<div id=”SH” class=”grp”>Information to show/hide</div>
[/code]

and toggle the display with a button like:

[code=php]
<button onClick=”Toggle(‘SH’)”>Show / Hide</button>
[/code]

The function to Show / Hide is defined as:

[code=php]
function Toggle(Info) {
CState = document.getElementById(Info);
if (CState.style.display == “none”) { CState.style.display = “block”; }
else { CState.style.display = “none”; }
}
[/code]

With the definitions out of the way, now comes my questions:
1. The contents of the <div> tag are initially not hidden. Why? I thought they would be by the <style> definitions
2. With the above, the very 1st click on the button does nothing,
but all subsequent clicks work as desired in that the contents of the <div> tag are toggled as hidden or displayed. Why? I thought the initial test would see “none” and change to “display”.
3. What don’t I understand about the CSS rules that if I change the <div> to this:

[code=php]
<div id=”SH” class=”grp” style=”display:none”>Information to show/hide</div>
[/code]

all works perfect with the initial contents of the <div> tag initially not shown and then are displayed with the 1st button click? What am I not understanding about the logic or set-up of the CSS style or tag definitions?

Thank you for any enlightnment.

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@LeeUMay 31.2007 — Try using:
[CODE]
div.grp {
visibility: hidden;
}[/CODE]
Copy linkTweet thisAlerts:
@JMRKERauthorMay 31.2007 — I tried that with no difference other than there were big gaps of space where the <div class="grp"...> tags were that would be filled on the 2nd click of the mouse with the 'hidden' text.

I think it is cleaner looking without the holding space when the <div...> area is made 'visible' and the 1st click problem remains.

Thanks for the attempt to help, any other ideas?
Copy linkTweet thisAlerts:
@JMRKERauthorJun 01.2007 — Just for reference, I got a 'solution' from the JS forum arena.

See: http://www.webdeveloper.com/forum/showthread.php?p=759856#post759856
×

Success!

Help @JMRKER 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...