Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1128 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Styled Radios using jQuery & CSS

Thread title: Styled Radios using jQuery & CSS
Reply    
    Thread tools Search this thread Display Modes  
01-02-2010, 11:19 AM
#1
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old  Styled Radios using jQuery & CSS

Example

Have a play with both the checkbox and radio sections to notice the problem.

I'm trying to remove the fakeradioed class from all radios that are unselected by another radio being selected.

Code:
$(document).ready(function(){
		// check for what is/isn't already checked and match it on the fake ones
		$("input:radio").each( function() {
			(this.checked) ? $("#fake"+this.id).addClass('fakeradioed') : $("#fake"+this.id).removeClass('fakeradioed');
		});
		// function to 'check' the fake ones and their matching checkboxes
		$(".fakeradio").click(function(){
			($(this).hasClass('fakeradioed')) ? $(this).removeClass('fakeradioed') : $(this).addClass('fakeradioed');
			$(this.hash).trigger("click");
			return false;
		});
	});
Any suggestions on how i can fix this?

Reply With Quote
01-02-2010, 11:46 AM
#2
hjalmar is offline hjalmar
Status: Senior Member
Join date: Nov 2004
Location: Sweden
Expertise:
Software:
 
Posts: 857
iTrader: 11 / 100%
 

hjalmar is an unknown quantity at this point

  Old

Where exactly are you "trying" to remove all the classes. Just remove the classes... seeing you've done it this far you should already know the rest.

Maybe you have missunderstood the "this" keyword?

Reply With Quote
01-02-2010, 12:24 PM
#3
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

heh, i think i have missunderstood it. (:

I'll go read up on it.

Reply With Quote
01-02-2010, 01:49 PM
#4
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Okay no idea.

Reply With Quote
01-02-2010, 02:31 PM
#5
hjalmar is offline hjalmar
Status: Senior Member
Join date: Nov 2004
Location: Sweden
Expertise:
Software:
 
Posts: 857
iTrader: 11 / 100%
 

hjalmar is an unknown quantity at this point

  Old

To make it short, the this keyword is refering to object itself (kinda). In your case that object is the html element. So the only thing that will be affected is the element that is triggered by your eventhandler.

What you are asking is that you want to remove the class from all the sibling selectors, right?

Reply With Quote
01-02-2010, 02:35 PM
#6
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Yeah but the single selected radio. Hmm.

Reply With Quote
01-02-2010, 03:28 PM
#7
Gurnk is offline Gurnk
Status: Member
Join date: May 2007
Location: US
Expertise:
Software:
 
Posts: 380
iTrader: 12 / 100%
 

Gurnk is on a distinguished road

Send a message via AIM to Gurnk Send a message via MSN to Gurnk

  Old

You just need to remove all the classes before you apply the clicked class to the one that's actually clicked.

Code:
$(".fakeradio").click(function(){
      $( 'ul a' ).removeClass( 'fakeradioed' );
      /* Continue with what you had */
)};

Reply With Quote
01-02-2010, 04:05 PM
#8
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Thank you. (:

This is what 30+ hours without sleep does to you.

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed