Link to home
Start Free TrialLog in
Avatar of D4Ly
D4Ly

asked on

referencing elements without ID's

If I have HTML like this

<ul>
        <li><a href="javascript://" title="Toggle" onclick="menu_toggle();">1</a>
            <ul id="one">
                  <li>1a</li>
                  <li>1b</li>
                  <li>1c</li>
                  <li>1d</li>
            </ul>
      </li>
      <li><a href="javascript://" title="Toggle" onclick="menu_toggle();">2</a>
            <ul id="two">
                  <li>2a</li>
                  <li>2b</li>
                  <li>2c</li>
            </ul>
      </li>
</ul>

What is the best way to do the following:
1) Pass a refrence to the menu_toggle function for the <a> element being clicked.
2) Select the parent element (the <li> that the link is nested in)
3) select the <ul> within that <li>

The addition of id's and such is not allowed!! Thanks!!
Avatar of sam85281
sam85281

Not really clear on all your questions/what you're asking for but best way to pass reference to the function is:

<a href="javascript:void(0);" title="Toggle" onclick="menu_toggle(1);">1</a>

Would help to see your toggle_menu() function but rebuild it something like:

function menu_toggle (linkID) {
if (linkID == 1) {
// do this
} else if (linkID == 2) {
//do this
}
}

If I'm missing your point altogether...please provide more details of whay you're trying to accomplish.

-Sam
SOLUTION
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D4Ly

ASKER

Smaccari-
Perfect! And the next step for me was in fact to add the display :) Thanks much, have a great day. I will give some credit to pravinasar, weighted to you for the simpler solution. Thanks!!!

- D4