开发者

Shortest way to write this (jQuery)

Is there any chainable method / way to write this in one line

var $d = $('<div>').addClass('开发者_Python百科clear');
$('.clearAfter').after($d);

The following will add css style to clearAfter rather

$('.clearAfter').after('<div>').addClass('clear');


You can use insertAfter:

$('<div>').addClass('clear').insertAfter('.clearAfter');

Or you can simply do:

$('.clearAfter').after('<div class="clear" />');


You can use insertAfter, which I find the most readable:

$('<div />').addClass('clear').insertAfter('.clearAfter');

Or, less pretty:

$('.clearAfter').after($('<div>').addClass('clear'));


What about

$('.clearAfter').after($('<div>').addClass('clear'));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜