开发者

remove the class to an item

开发者 https://www.devze.com 2023-03-31 05:04 出处:网络
Hi I need to remove the class \'fancy\' to all fancy items, <script type=\"text/javascript\"> $(document).ready(function(){

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'); } );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号