Link to home
Start Free TrialLog in
Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America

asked on

Toggle only certain anchor

I have this HTML:
<li id="toggle">
  <a href="/store/customer/account/logout/">Logout</a>
  <a id="close" style="display: none;" class="close" href="#">Close Panel</a>
</li>

Open in new window

Sometimes the first anchor will be like this:
  <a id="open" class="open" href="#">Log In | Create Account</a>

I have a click event to toggle the wording like this:
// Switch buttons from "Log In | Register" to "Close Panel" on click
$("#toggle a").click(function(event) {
  event.preventDefault(); 
  $("#toggle a").toggle();
});

Open in new window

How would I trigger the toggle() only when the first anchor has an id = 'open'?
ASKER CERTIFIED SOLUTION
Avatar of effx
effx
Flag of United Kingdom of Great Britain and Northern Ireland 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
SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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
I understood the requirement was for the toggle function not the click function
Avatar of Eddie Shipman

ASKER

Actually did it a little different but both answers helped me.