Toni Michel Caubet
Toni Michel Caubet

Reputation: 20163

remove the class to an item

Hi I need to remove the class 'fancy' to all fancy items,

<script type="text/javascript">
$(document).ready(function(){
    $('.fancy').removeClass('.fancy');
    alert($('.fancy').length + 'comentarios');
});
</script>

Trying like that, the class is not removed and the alert shows me '6comentarios' so there are 6 items selected,

what am i missing??

thanks!

Upvotes: 0

Views: 65

Answers (4)

Sebastian Wramba
Sebastian Wramba

Reputation: 10127

You are removing the class from an array of objects. That will probably not work. Try the each() function.

$('.fancy').each( function() { this.removeClass('fancy'); } );

Upvotes: -1

stewe
stewe

Reputation: 42632

You have to use fancy instead of .fancy inside of removeClass()

Upvotes: 0

genesis
genesis

Reputation: 50976

$('.fancy').removeClass('fancy');

will work. Dot before className means "class", so in this case (removeClass) it's not allowed/required

demo

Upvotes: 0

cillierscharl
cillierscharl

Reputation: 7117

You don't have to provide a selector as an argument, simply a class name.

Try:

$('.fancy').removeClass('fancy');

Upvotes: 5

Related Questions