Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Using javascript to show and hide DIV
Old 08-10-2006, 10:18 AM Using javascript to show and hide DIV
Novice Talker

Posts: 12
Trades: 0
Hi.

On my website, I have a news section. There are four little "thumbnail" images that the user can click to view news. For example if the user clicking "news1.jpg" I need that to be able to display the DIV "news1". Now say the user clicking the "news3.jpg". I now need it to hide the "news1" DIV and unhide the "news3" DIV. Im kind of stumped of how to do this.

Can anybody help?

Thank You.

Last edited by MIDNIGHTBANDIT9; 08-10-2006 at 10:20 AM..
MIDNIGHTBANDIT9 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-10-2006, 12:56 PM Re: Using javascript to show and hide DIV
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
<a href="#" onclick="toggleDiv('news1');">(image 1)</a>

And your Javascript (a quick rough cut...I'd suggest making it better as you go along.)
Code:
function toggleDiv(divId) {
     for (var i = 1; i < 4; i++) {
          var tempDivId = "news" + i;
          document.getElementById(tempDivId).style.display = 'none'; // this makes all the divs invisible so that none overwrite each other.
     }
     document.getElementById(divId).style.display = 'block';
     return false; // this should avoid accidental clickthroughs if you make the link an active link to something else. Not necessary.
}
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to Using javascript to show and hide DIV
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09584 seconds with 12 queries