Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-20-2009, 03:37 PM   PM User | #1
stylepile
New to the CF scene

 
Join Date: Nov 2009
Location: Milwaukee
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
stylepile is an unknown quantity at this point
using show/hide and need toggle clicked link class

I am using the script below to show and hide three divs using three links. What I would like to know is how to add a class to the currently clicked link and then remove it when one of the other links is clicked.

Code:
$(document).ready(function(){
	var divs = $('div.recommended_block, div.buying_advice_block, div.brand_reviews_block').hide();
	$('div.recommended_block').show();
	$('a#recommended_block, a#buying_advice_block, a#brand_reviews_block').click(function() {
 	 	divs.filter(':visible').hide();
  		$('.' + this.id).show();
  		return false;
	});
}); 
stylepile is offline   Reply With Quote
Old 11-20-2009, 05:21 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
One way would be whenever a link is clicked, apply the "off" class to all the links, then apply the "on" class to just the clicked link (accessable via $(this)).
__________________
Fumigator is offline   Reply With Quote
Old 11-20-2009, 05:54 PM   PM User | #3
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Using Fumigator's suggested method with toggleClass() makes this super easy.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 11-20-2009, 08:19 PM   PM User | #4
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Quote:
Originally Posted by tomws View Post
Using Fumigator's suggested method with toggleClass() makes this super easy.
Oh, right on, good idea. I wouldn't have thought to use that one.
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Tags
class change, jquery, show/hide

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Advertisement
Log in to turn off these ads.