Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the listItem, would this be something like:

    document.getElementById('Menu') cause that doesnt work for me,

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.....

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nah, thanks alot brothercake, but that script is way over my head


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •