Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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