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
https://forums.phpfreaks.com/topic/218777-help-please/
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
https://forums.phpfreaks.com/topic/218777-help-please/#findComment-1134694
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
https://forums.phpfreaks.com/topic/218777-help-please/#findComment-1135560
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.