June 18, 2013

Selecting more than one option

User2386255’s Question:

I have the following code working pretty well, but I want to be able to select more than one option if need be: http://jsfiddle.net/exlondoner/MKa3n/

Can anyone help?

JS:

$('.media-select-option').on('click', function() {
    $('.media-select-option').removeClass('selected');
    $(this).addClass('selected');     
    $('.m-overlay-close-btn').addClass('checked');       
});

Try this:

$('.media-select-option').on('click', function () {
    $(this).toggleClass('selected');
    $('.m-overlay-close-btn').addClass('checked');
});

FIDDLE

It is not working because there is no such element with class m-overlay-close-btn

$('.overlay-close-btn').addClass('checked');

Working fiddle

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!