/    Sign up×
Community /Pin to ProfileBookmark

Show/hide divs help needed Javascript

Hello,

I have the following code to hide and show div’s in the same page
but doesn’t work. Can anybody help? Thank you

[B][U][COLOR=”#FF0000″]JAVASCRIPT CODE:[/COLOR][/U][/B]

var active = null;
function hideAll() {
hide(“info”);
}
function hide(id) {
var el = document.getElementById(id);
if(el) el.style.display=”none”;
document.getElementById(“more”+id).innerHTML=”MORE…”;
}
function show(id) {
hideAll();
if (active == id) {
hide(active);
active = null;
}
else {
document.getElementById(“more”+id).innerHTML=”CLOSE”;
document.getElementById(id).style.display=””;
active = id;
}
}

var active = null;
function hideAll() {
hide(“info2”);
}
function hide(id) {
var el = document.getElementById(id);
if(el) el.style.display=”none”;
document.getElementById(“more”+id).innerHTML=”MORE…”;
}
function show(id) {
hideAll();
if (active == id) {
hide(active);
active = null;
}
else {
document.getElementById(“more”+id).innerHTML=”CLOSE”;
document.getElementById(id).style.display=””;
active = id;
}
}

var active = null;
function hideAll() {
hide(“info3”);
}
function hide(id) {
var el = document.getElementById(id);
if(el) el.style.display=”none”;
document.getElementById(“more”+id).innerHTML=”MORE…”;
}
function show(id) {
hideAll();
if (active == id) {
hide(active);
active = null;
}
else {
document.getElementById(“more”+id).innerHTML=”CLOSE”;
document.getElementById(id).style.display=””;
active = id;
}
}

[B][U][COLOR=”#FF0000″]HTML CODE:
[/COLOR]
[/U]
[/B]

<a id=”moreinfo” href=”#” onclick=”javascript:show(‘info’); return false;”>MORE…</a>
<div id=”info” style=”display: none”> Info</div>
<a id=”moreinfo” href=”#” onclick=”javascript:show(‘info2’); return false;”>MORE…</a>
<div id=”info2″ style=”display: none”> Info2</div>
<a id=”moreinfo” href=”#” onclick=”javascript:show(‘info3’); return false;”>MORE…</a>
<div id=”info3″ style=”display: none”> Info3</div>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERSep 10.2012 — Couple of problems.

1. You have 3 functions with the same name: hideall(), hide() and show()

Computer will probably only go to the last one defined.

  • 2. In the body section, you have identical id values (moreinfo). Not allowed.

    ID values must be unique.
  • ×

    Success!

    Help @Webill 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.18,
    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,
    )...