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
Closing a div id when opening a new link?
Old 05-06-2009, 09:01 PM Closing a div id when opening a new link?
MellowD's Avatar
Average Talker

Posts: 15
Trades: 0
I'm building a site where the links open up div boxes so the user doesn't actually have leave the page when clicking the link. I figured out how to open a div when clicking a link but need to figure out how to close any open div's when clicking a new link (so there aren't a bunch of div boxes open). I tried searching but haven't found much info. Any help would be greatly appreciated. Here is the code below.


<a href="#" onclick="document.getElementById('moreinfo').style .display = 'block';">Link Goes Here</a>

<div><script type="text/javascript"><!--
document.write("<div style='display:none' id='sampleid>");
//-->
</script>Content Going Here<script type="text/javascript"><!--
document.write("</div>");
//--></script></div>
MellowD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-06-2009, 09:22 PM Re: Closing a div id when opening a new link?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
This method uses javascript with CSS class names. Hopefully it helps you to figure out your particular page.

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script type="text/javascript">
    var toggle_divs_prefix = 'div_'; //The prefix of id values for controlled divs
      function toggleDivs(active_div) {
        var page_divs = document.getElementsByTagName('div');
        if (page_divs.length > 0) {
          for (var i=0;i < page_divs.length;i++) {
            page_divs[i].className = page_divs[i].className.replace(/dynamic\_div\_visible/,"dynamic_div_hidden");
          }
          document.getElementById(toggle_divs_prefix + active_div).className = document.getElementById(toggle_divs_prefix + active_div).className.replace(/dynamic\_div\_hidden/,"dynamic_div_visible");
        }
      }
    </script>
    <style>
      .dynamic_div_visible {
      }
      .dynamic_div_hidden {
        display:none;
      }
      .featured {
        border:3px #000099 inset;
      }
    </style>
  </head>
  <body>
    <a href="javascript:toggleDivs(1);">Show Div 1</a>
    <a href="javascript:toggleDivs(2);">Show Div 2</a>
    <a href="javascript:toggleDivs(3);">Show Div 3</a>
    <div id="div_1" class="dynamic_div_visible">
      <h1>Div 1</h1>
    </div>
    <div id="div_2" class="featured dynamic_div_hidden">
      <h1>Div 2</h1>
    </div>
    <div id="div_3" class="dynamic_div_hidden">
      <h1>Div 3</h1>
    </div>
  </body>
</html>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-07-2009, 01:30 AM Re: Closing a div id when opening a new link?
MellowD's Avatar
Average Talker

Posts: 15
Trades: 0
Wow, Thanks so much Jeremy! Exactly what I was looking for. Thanks!!!
MellowD is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Closing a div id when opening a new link?
 

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.22598 seconds with 12 queries