?
Solved

Toggle only certain anchor

Posted on 2011-10-26
4
Medium Priority
?
261 Views
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>
</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'?
0
Comment
Question by:Eddie Shipman
  • 2
4 Comments
 
LVL 10

Accepted Solution

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

Assisted Solution

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

Expert Comment

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

Author Closing Comment

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

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