Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding Current Div

Status
Not open for further replies.

jrottman

Programmer
Jun 17, 2005
47
0
0
I am working on a small app. And I have ran into an issue. How can I hide the current div that is being displayed when I click on a link, and load the new div.
 
Using javascript you change the display css property of the div to none. This is all I can tell you with the information you provided us.
 
Here is a wee example you might be able to follow...
Code:
<div id="div_one">This is some text in div 1</div>
<a href="javascript:document.getElementById('div_one').style.display = 'none';document.getElementById('div_two').style.display = 'block';">Click for next...</a>
<div id="div_two" style="display:none;">This is some more text in div 2</div>

Harry
 
Code:
<div id="div_one">This is some text in div 1</div>
<a [COLOR=red]href="#" onclick=[/color]"javascript:document.getElementById('div_one').style.display = 'none';document.getElementById('div_two').style.display = 'block'">Click for next...</a>
<div id="div_two" style="display:none;">This is some more text in div 2</div>

might be better ?
 
Well, ideally you would offer a solution that used onclick for javascript users (with a return false at the end) and degraded for non-javascript users... where you would use the href part of the anchor...
Code:
<a href="?showdiv=2" onclick="document.getElementById('div_one').style.display = 'none';document.getElementById('div_two').style.display = 'block';return false;">Click for next...</a>
You would code the page server-side to deliver some inline CSS to the first div, and not for the second div (in the example we are using above).

Just as a note... you do not need to put "javascript:" inside an onclick event [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
yeah, eerrm, well thats the way I would have done it too, ahem..... :)
 
Well the issue that I have run into is that, I wont know the current active div. All my links are dynamically generated on the fly. And I wont know what the current active div is.

Is there anyway to do something like currentActive element?
 
You'd just create a javscript function that accepted the current div as a parameter.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top