addClass and removeClass in a switch case Since I'm still learning jQuery, I would like to have some feedback on my code:



var showImgage = function()
{
 var selection = $(this).val();
 
 switch(selection) 
 {
  case 'Monica Bellud':
  $('#Belluci').removeClass().addClass('show');
  $('#Andres').removeClass().addClass('hide');
  $('#Seydoux').removeClass().addClass('hide');
  break
  
  case 'Lea Seydoux':
  $('#Seydoux').removeClass().addClass('show');
  $('#Belluci').removeClass().addClass('hide');
  $('#Andres').removeClass().addClass('hide');
  break
  
  case 'Ursula Andress':
  $('#Andres').removeClass().addClass('show');
  $('#Belluci').removeClass().addClass('hide');
  $('#Seydoux').removeClass().addClass('hide');
  break
  
  default:
  selection.removeClass();
 }
}
&lt;div&gt;
  &lt;label for = "bondgirl"&gt;Wie van de onderstaande dames is géén Bond Girl in de nieuwe film 'SPECTRE'?&lt;/label&gt;
  &lt;input type="radio" value="Monica Bellud" name="girlchoice" id="choicemonica" checked /&gt;&lt;label for="choicemonica" class="sidelabel"&gt;Monica Bellud&lt;/label&gt;
  &lt;input type="radio" value="Lea Seydoux" name="girlchoice" id="choicelea" /&gt;&lt;label for="choicelea" class="sidelabel"&gt;Lea Seydoux&lt;/label&gt;
  &lt;input type="radio" value="Ursula Andress" name="girlchoice" id="choiceursula" /&gt;&lt;label for="choiceursula" class="sidelabel"&gt;Ursula Andress&lt;/label&gt;
&lt;/div&gt;




I simply want to change the image (which is in my div of my HTML) for each radiobutton. It works, but it looks like I'm duplicating my code 3 times. How can I make this easier?
I would probably add a class/something to use as a selector (in this case I added girls) to make lookup easier. You can do this in other ways such as getting the values of the actors map so do it as you will.

Also your default case is calling removeClass on a string as selection is the current contents of whatever the event is hooked to.

// Actor name -&gt; the corresponding element selector on the page
var actorsIdMap = {
    'Monica Bellud': '#Bellud',
    'Lea Seydoux': '#Seydoux',
    'Ursula Andress': '#Andres' 
}

var showImage = function() {
    var selection = $(this).val();

    if (selection in actorsIdMap) {    
        // Hide the other actors
        $('.girls').removeClass('hide show');
        $(actorsIdMap[selection]).addClass('show');
    } else {
       // Default case what do?
    }
}