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 al开发者_开发百科ert shows me '6comentarios' so there are 6 items selected,
what am i missing??
thanks!
You don't have to provide a selector as an argument, simply a class name.
Try:
$('.fancy').removeClass('fancy');
$('.fancy').removeClass('fancy');
will work. Dot before className means "class", so in this case (removeClass) it's not allowed/required
demo
You have to use fancy
instead of .fancy
inside of removeClass()
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'); } );
精彩评论