WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > PROGRAMMING LANGUAGES > Scripting and Server Side > [SOLVED] 2 IDs for getElementById?

Reply
  Thread Tools Display Modes
Old 27th October 12, 12:36 AM   #1
Zeaks
WLC Lover
 
Zeaks's Avatar
 
Join Date: Sep 2010
Location: Canada
Posts: 59
Default 2 IDs for getElementById?

I've added a second (mobile)menu to a Wordpress theme, it works fine, but I know I could of done better with the javascript. I've very new to javascript.

Basically I need to add a second ID to getElementById

to get around this, I've just copied the entire js and changed the ID. Is there a better way to do this?

This is the section I need to change the 'site-navigation' part, I need it to also include 'lower-navigation'

Code:
var button = document.getElementById( 'site-navigation' ).getElementsByTagName( 'h3' )[0],
	    menu   = document.getElementById( 'site-navigation' ).getElementsByTagName( 'ul' )[0];
Here is the full .js file http://pastebin.com/PmAsjUg7

Last edited by Zeaks; 27th October 12 at 12:37 AM. Reason: typo
Zeaks is offline   Reply With Quote
Old 27th October 12, 03:42 PM   #2
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,711
Default Re: 2 IDs for getElementById?

Why not determine which ID it's using, assign it to a variable, and then use that with the getElementById(variable)?
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 27th October 12, 05:02 PM   #3
Zeaks
WLC Lover
 
Zeaks's Avatar
 
Join Date: Sep 2010
Location: Canada
Posts: 59
Default Re: 2 IDs for getElementById?

Quote:
Originally Posted by meesa View Post
Why not determine which ID it's using, assign it to a variable, and then use that with the getElementById(variable)?
I know what ID it's using, #site-navigation, i need it to also include #lower-navigation. from what I've read I can't just use
Code:
var button = document.getElementById( 'site-navigation', 'lower-navigation' ).getElementsByTagName( 'h3' )[0],
	    menu   = document.getElementById( 'site-navigation', 'lower-navigation').getElementsByTagName( 'ul' )[0];
That's why I mentioned I'm very new to javascript, I don't know the proper way to add another ID to the code.
Zeaks is offline   Reply With Quote
Old 27th October 12, 05:06 PM   #4
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,711
Default Re: 2 IDs for getElementById?

Something along the lines of:

Code:
var ID="";
if(ID1 Exists) { ID=ID1; }
else if(ID2 Exists){ ID=ID2; }

getElementById(ID);
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 27th October 12, 10:44 PM   #5
Zeaks
WLC Lover
 
Zeaks's Avatar
 
Join Date: Sep 2010
Location: Canada
Posts: 59
Default Re: 2 IDs for getElementById?

Thank you
Zeaks is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:09 PM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyrightę 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.