开发者

Shortest way to write this (jQuery)

开发者 https://www.devze.com 2023-03-31 05:48 出处:网络
Is there any chainable method / way to write this in one line var $d = $(\'<div>\').addClass(\'开发者_Python百科clear\');

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

精彩评论

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