Jump to content

Help Please


neilfurry

Recommended Posts

Im having this problem and dont know how to figure out,

 

first i have five links on my page, then each link is assigned a hidden div, then when i click on the first link the div designated to that link will show, now, the problem is when i clicked the other links the previous div still show, now, please anyone help me.. i want to make it so that when i clicked on different link, only the designated div will show and it ill close the previously opened div.. :shrug:

 

kindly help please..

 

Thanks

Link to comment
Share on other sites

Here is an example:

<html>
<head>
<script type="text/javascript">

function showDiv(selectedDivNo)
{
    var divNo = 1;
    while(document.getElementById('div_'+selectedDivNo))
    {
        document.getElementById('div_'+divNo).style.display = (divNo==selectedDivNo) ? 'inline' : 'none';
        divNo++
    }
    return false;
}

</script>

</head>
<body>
<a href="#" onclick="return showDiv(1);">Show div 1</a>
<a href="#" onclick="return showDiv(2);">Show div 2</a>
<a href="#" onclick="return showDiv(3);">Show div 3</a>
<a href="#" onclick="return showDiv(4);">Show div 4</a>
<a href="#" onclick="return showDiv(5);">Show div 5</a>
<br />
<div id="div_1" style="display:none;">Div 1</div>
<div id="div_2" style="display:none;">Div 2</div>
<div id="div_3" style="display:none;">Div 3</div>
<div id="div_4" style="display:none;">Div 4</div>
<div id="div_5" style="display:none;">Div 5</div>
</body>
</html>

Link to comment
Share on other sites

function showDiv(selectedDivNo)
{
    var divNo = 1;
    while(document.getElementById('div_'+divNo))
    {
        document.getElementById('div_'+divNo).style.display = (divNo==selectedDivNo && document.getElementById('div_'+divNo).style.display=="none") ? 'inline' : 'none';
        divNo++
    }
    return false;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.