Toggle only certain anchor

Posted on 2011-10-26
Medium Priority
Last Modified: 2012-05-12
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>

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) {
  $("#toggle a").toggle();

Open in new window

How would I trigger the toggle() only when the first anchor has an id = 'open'?
Question by:Eddie Shipman
  • 2
LVL 10

Accepted Solution

effx earned 1000 total points
ID: 37034663
$("#toggle a").click(function(event) {
  $("#toggle a#open").toggle();
LVL 83

Assisted Solution

leakim971 earned 1000 total points
ID: 37034689
// Switch buttons from "Log In | Register" to "Close Panel" on click
$("#toggle a#open").click(function(event) {
  $("#toggle a").toggle();
LVL 10

Expert Comment

ID: 37034706
I understood the requirement was for the toggle function not the click function
LVL 26

Author Closing Comment

by:Eddie Shipman
ID: 37038129
Actually did it a little different but both answers helped me.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question