Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-21-2004, 02:51 AM   PM User | #1
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
Use JS to select a li inside a li

How could I use JS to select a <ul> element which is inside a <li> element?
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Old 04-21-2004, 03:32 AM   PM User | #2
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
You can use getElementsByTagName from any root element, so if you start from your list-item then the nested <ul> will be [0] in that array:
Code:
var submenu = listItem.getElementsByTagName('ul')[0];
Assuming you know it will be there. If you don't then you can query the length property of that collection before grabbing the object from it, or not:
Code:
var menus = listItem.getElementsByTagName('ul');
var submenu = (menus.length > 0) ? menus[0] : null;
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
brothercake is offline   Reply With Quote
Old 04-21-2004, 12:12 PM   PM User | #3
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
the listItem, would this be something like:

document.getElementById('Menu') cause that doesnt work for me,
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Old 04-21-2004, 01:12 PM   PM User | #4
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
I give up:

Brother cake, how did you manage to build you udm on this basis?:
Code:
<ul>
	<li><a href="#">lorem</a></li>
	<li><a href="#">lorem</a></li>
	<li><a href="#">lorem</a></li>
	<li>
		<a href="#">adipiscing</a>
		<ul>
			<li><a href="#">dolor</a></li>
			<li><a href="#">elit</a></li>
			<li><a href="#">ipsum</a></li>
			<li><a href="#">Donec</a></li>
		</ul>
	</li>
</ul>
thanks alot, I have been trying to select the UL with js, when i hover over the LI, but then the A tag gets in the way (which is in the LI tag), but then i no longer hover over a li tag, i hover of the a tag...

soo please tell me how you manage to do it....

thanks alot
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Old 04-25-2004, 08:20 AM   PM User | #5
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Well have you seen the prototype I made at http://www.brothercake.com/scripts/listmenu/ ? That'll give you the basic event handling model.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
brothercake is offline   Reply With Quote
Old 04-25-2004, 02:49 PM   PM User | #6
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
thanks, I am working on MY menu right now, I thought it can do everything yours can do but then i saw that i have about 1/10000 of your code, about 10 lines of JS, I MUST be missing something

....dude, very nice menu , love it.....
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Old 04-25-2004, 05:22 PM   PM User | #7
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Nah that link is to a much earlier version - it only has a dozen lines of scripting in it. I only suggested you look at it to see how I bound the event handlers to the list items and managed the flow of events.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
brothercake is offline   Reply With Quote
Old 04-25-2004, 09:00 PM   PM User | #8
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
Nah, thanks alot brothercake, but that script is way over my head
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 01:21 AM.


Advertisement
Log in to turn off these ads.