Samza Posted May 28, 2013 Share Posted May 28, 2013 Hey guys! I am trying to achieve the following functionality; Use javascript to display page content that is stored on one page by showing the requested content through the navigation, i.e. clicking the Home link, and making the previous page content invisible. I have been playing around with altering the CSS styling off the div's. I have 3 div's each name; Home, Portfolio and Enquire. Here is the CSS for them; #home { display: block; } #portfolio { display: none; } #enquire { display: none; } So from this the home div is the first that is seen when the page loads. Now using the navigation I have I am calling a function; <nav class="row"> <ul> <li class="above-border"> </li> <li class="nav-smallfont">about</li> <li><a href="javascript:toggle_visibility('portfolio');" alt="Portfolio" target="_self">PORTFOLIO</a></li> <li class="above-border"> </li> <li class="nav-smallfont">back</li> <li><a href="javascript:toggle_visibility('home');" alt="Homepage" target="_self">HOME</a></li> <li class="above-border"> </li> <li class="nav-smallfont">furniture</li> <li><a href="#" onclick="toggle_visibility('enquire');" alt="Enquire" target="_self">ENQUIRE</a></li> <li class="above-border"> </li> </ul> </nav> I was playing around with the difference between onclick and javascript: - I didnt really see any major difference. Now my Javascript is this; <script type="text/javascript"> function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == 'block'){ e.style.display = 'none'; } else{ e.style.display = 'block'; } } </script> Now whenever I click on the home navigation it will show/hide the content and when I click on say, the portfolio link it will show this content as well as the home. Im pretty sure you understand what I am hoping to achieve; A navigation style functionality so that when the portfolio link is click, it hides the other content and show only that and visa versa for the other links. Thanks for your help! Sam Quote Link to comment https://forums.phpfreaks.com/topic/278479-displaying-page-content-using-javascript/ Share on other sites More sharing options...
Jessica Posted May 28, 2013 Share Posted May 28, 2013 Dear god, is this really what they're teaching in schools? *smh* Quote Link to comment https://forums.phpfreaks.com/topic/278479-displaying-page-content-using-javascript/#findComment-1432754 Share on other sites More sharing options...
Irate Posted May 28, 2013 Share Posted May 28, 2013 javascript: URLs are hopelessly outdated and shouldn't be used. Try to use unobstrusive JavaScript, or, ideally, use jQuery, that's much easier. Quote Link to comment https://forums.phpfreaks.com/topic/278479-displaying-page-content-using-javascript/#findComment-1432756 Share on other sites More sharing options...
Adam Posted May 28, 2013 Share Posted May 28, 2013 Mmm.. did you actually ask a question at any point? Quote Link to comment https://forums.phpfreaks.com/topic/278479-displaying-page-content-using-javascript/#findComment-1432770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.