Hello, long time lurker, first time poster here. I need some help with something that's been driving me batty lately (also fairly new to the world of js):
I have two buttons and two menus that are nested inside the same div. What I would like to happen is when one button is clicked the former menu disappears and is replaced with the other menu and the other way around.
The closest example of what I'm talking about are the "About" "Share" and "Add To" buttons on youtube, but I don't really care for the slide animation.
Also I need each button to have an active state.
Whew! This is probably something stupidly easy, but I'm a js newb so I would really appreciate any and all help in this matter
You have provided a bunch of requirements, but very little code.
For that reason, you get what I THINK you want. Modify to your heart's content.
I don't use youtube very often, so I'm not sure I understand the layout design.
The active state of each menu would be 'block' or 'none' in the following code.
Thanks for the replies! Both examples look promising and I look forward to trying them out.
I realize I didn't post any code because at this point I don't have any useful to show at this point. I'm sure this will change when i start coding the new menu with the suggested additions.
Also, how would I add an active state to the selected button?
Okay I tried both scripts and jmrker is closest to what I am talking about, however it neither one will work in IE 8 which is what I'm currently using. Both run fine in non-IE browsers.
What could be the problem?
Once again the script works great, but I have a couple of questions about the script in your second script posting since I'm the type who likes to know how and why a script works rather than just copying and pasting:
What is the purpose of the parameters in both the buttons and functions?
Once again the script works great, but I have a couple of questions about the script in your second script posting since I'm the type who likes to know how and why a script works rather than just copying and pasting:
What is the purpose of the parameters in both the buttons and functions?
Thanks again!
First off, you're most welcome. Happy to help.
Concerning the 2 arguments in the button function.
The 1st controls the specific <div> tag associated with the particular menu to display.
The 2nd controls the current button. Allows controls of the background-Color with the CSS style.display
Okay that makes sense to me, but why are the parameters given different names in the actual function (IDS,info) and why is 'this' used in place of 'info' in the buttons?
Did I mention I'm fairly new to javascript? Thanks!
Okay that makes sense to me, but why are the parameters given different names in the actual function (IDS,info) and why is 'this' used in place of 'info' in the buttons?
Did I mention I'm fairly new to javascript? Thanks!
The IDS refers to the appropriate <div id='xxx' ....> element.
The 'this' refers to the button element. 'info' is the placeholder for 'this' in the function being called.
Two different elements, hence two different parameters.
Very cool. The IDS parameter makes sense to me because it is encompassing two different ids.
I guess I was confused to why 'info' wasn't used in the button function instead of 'this', but 'this' actually refers to the button element itself, which is then represented in the actual function as 'info' and that is how javascript knows which element to make the changes to in regards to the 'info' placeholder.