user3162496
user3162496

Reputation: 11

.removeClass on multiple items?

Can I rewrite the code below to something less repetitive?

    $("#iTUNES").click(function()
{
    createLastEdition(26);
    $("#Beatport").removeClass("Active");
    $("#Spotify").removeClass("Active");
    $("#Youtube").removeClass("Active");
    $("#iTunes").addClass("Active");
});

For example something like this

$("#Beatport","#Spotify,"#Youtube").removeClass("Active") 

?

Upvotes: 0

Views: 58

Answers (3)

Fizer Khan
Fizer Khan

Reputation: 92935

You can use active class itself to remove active class

$(".Active").removeClass("Active");
$("#iTunes").addClass("Active");

Upvotes: 1

Pointy
Pointy

Reputation: 414056

You can combine selectors with standard CSS syntax:

$("#Beatport, #Spotify, #Youtube, #iTunes").removeClass("Active");

You might find it more convenient to categorize such related page elements with a class. Then you'd just need

$(".media-container").removeClass("Active");

Upvotes: 3

cubitouch
cubitouch

Reputation: 1937

These should work :

$("#Beatport","#Spotify","#Youtube").removeClass("Active");

or

$("#Beatport,#Spotify,#Youtube").removeClass("Active");

Upvotes: 0

Related Questions