开发者

Can this be written more elegantly?

I was wondering if a callback would work with this simple two line jquery below? I'm pretty new so I just am looking to get bett开发者_如何学Pythoner :)

Thanks!

jQuery('.entry:first').addClass('firstEntry');
jQuery('.entry:first').removeClass('big');


jQuery('.entry:first').addClass('firstEntry').removeClass('big');


jQuery('.entry:first').addClass('firstEntry').removeClass('big');


jQuery supports chaining...

jQuery('.entry:first').addClass('firstEntry').removeClass('big');

Also, note there is a .toggleClass() method.


You could do this:

jQuery('.entry:first').addClass('firstEntry').removeClass('big');


var $entries = $(".entry");
$entries.first().addClass('firstEntry').removeClass('big');

or something a bit more readable...

var $entries = $(".entry");
$entries
  .first()
    .addClass('firstEntry')
    .removeClass('big');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜