Jump to content

Displaying page content using Javascript


Samza

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

Archived

This topic is now archived and is closed to further replies.

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