I have a menu bar at the top of the page, and I want to change part of the page content upon clicking one of the menu buttons. I can't figure out how the program the JavaScript, I'm very new to programming. If someone could give me a hand that'd be awesome!
Here's the basic code below without any CSS. Not sure how to begin with the JavaScript.
Yeah they will be set to display:none in my CSS file. I was looking for example online and they all had the divs set to display:none, but I just couldn't understand what the code was doing or how it worked. I figured setting it to display:none would be the logical thing to do though since.
Now the thing is, when "home" is clicked, only the "home" HTML should be shown, and the rest should be hidden. Etc. will the code you gave me do that? I will give it a try after I get off work today.
Yes, it will, assuming all of them start with a style of none.
Probably you will want to show one of them by default, so call show('home'); at the end of the script as well so that it's the one that is shown when the page is first loaded. Here's an edited script for you that will show home by default:
Quick question. Say I wanted to hide a div with JavaScript. Could I switch out that "show();" function with something to "hide" the div instead of show it?
But how would I set that up using the onClick() command to hide the div? I'm assuming I can't just copy and past the original code and switch the var to something different because the function is still show().
I want it to work the same way as with the original code, just when the button it clicked, the div will be set to display:none;
I am going to keep trying to figure this out myself because I feel like a free-loader haha
EDIT: NEVERMIND! I figured it out. I wasn't aware that you could make the function yourself. I thought the the function was a pre-made JavaScript command. All I did was change the function name to "hide" and I changed the variable to "hidden." Then changed the display from block to none and it worked perfectly.... Now to figure out how to reference two divs in one "onclick()"
EDIT: Got it! onclick="hide('div');hide('div');"
Last edited by Mike Anthony; 04-10-2012 at 10:16 PM.
I too am starting my path learning JavaScript. Your question is just what I was asking and found your post. Thank you for asking these questions and posting your results they have helped me a lot. I would like to ask you though, when I load my page all the results are shown first then are hidden and display the right page once I click on the links. Do you know what I am missing to show just the Home page on load? I even used the on load option.
Bookmarks