/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Hide and Show <div>s

My page shall, when loaded, display Part 1 and Part 3 followed by button “Show Exercise”. Part 2 is hidden.
Clicking butten “Show Exercise” shall display Part 1 and Part 2 followed by button “Hide Exercise”. Part 3 is hidden.

Part 1 contains a sample text,
Part 2 contains some explanations relatad to the sample text, and
Part 3 contains an exercise related to the sample text.

How is the onclick to be scripted so that
display=”block” is changed to display=”none”, and
display=”none” is changed to display=”block”?
Thanks for your help.


<body>
<!– Part 1: a number of <p>s with text –>

<div class=”hidden” display=”none”>
<!– Part 2: a few <p>s and a <table> –>
<button type=”button” onclick=”???”>Show Exercise</button>
</div>

<div class=”shown”>
<!– Part 3: some <p>s with text –>
<button class= type=”button” display=”block” onclick=”???”>Hide Exercise</button>
</div>
</body>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@samliewOct 31.2007 — [code=html]<script type="text/javascript"><!--
function toggleDisplay(id) {
var e = document.getElementById(id);
(e.style.display=='none')?e.style.display='block':e.style.display='none';
}
//--></script>

<body>
<p>some text</p>

<div id="div1" style="display:none;">
div1
</div>
<div id="div2" style="display:block;">
div2
</div>
<input type="button" value="Show/Hide Exercise" onclick="toggleDisplay('div1');toggleDisplay('div2');" />
</body>[/code]
Copy linkTweet thisAlerts:
@nicoletauthorNov 11.2007 — Yes, it did help! It was exactly what I need. Thank you very much.

Greetings from Zurich, Switzerland.
×

Success!

Help @nicolet 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.20,
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,
)...