lundi 7 décembre 2015

jQuery If a variable is in array goto "Div" delete all classes in array

What i'm trying to do : Ok I'm trying to build a style switcher here is how it works.

I need help to check condition: If variable is in array goto "Div" delete all classes in array.

STRUCTURE:

// Radio Group 1 (color)

<input type="radio" name="color" id="red" >
<input type="radio" name="color" id="blue" checked>
<input type="radio" name="color" id="green">

Store each radio group in array color (all array names are same as radio group name)

var color = ['red','blue','green'];

// Radio Group 2 (size)

<input type="radio" name="size" id="fluid"  checked>
<input type="radio" name="size" id="boxed">

array of size

var size = ['fluid','boxed'];

example html:

 <div class" blue fluid"> 
    . . .
 </div> 

Get the user input

 var isChecked = $('#form').on('change',function(){
        isChecked = $(this).attr('id');
}

This is the if condition for each radio button where i am stuck now..

// if user select red

//---------------------

if( isChecked == 'red'){ 

     // remove any class(blue) from "Div" that match the value in array color[]. 
     // keep classes(fluid) as is if it's not in array color[]. 
     //---------------------------
     // add new class or ID to the DIV.

 }

// if user select red

//---------------------

if( isChecked == 'red'){ 

     // remove any class(blue) from "Div" that match the value in array color[]. 
     // keep classes(fluid) as is if it's not in array color[]. 
     //---------------------------
     // add new class or ID to the DIV.

 }

// if user select blue

//---------------------

if( isChecked == 'blue'){ 

     // remove any class(blue) from "Div" that match the value in array color[]. 
     // keep classes(fluid) as is if it's not in array color[]. 
     //---------------------------
     // add new class or ID to the DIV.

 }

// if user select green

//---------------------

if( isChecked == 'green'){ 

     // remove any class(blue) from "Div" that match the value in array color[]. 
     // keep classes(fluid) as is if it's not in array color[]. 
     //---------------------------
     // add new class or ID to the DIV.

 }

Aucun commentaire:

Enregistrer un commentaire