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'));
精彩评论