我有一个获取几个项目的选择器,我想向该堆栈添加一个元素。这不是pushStack的用途吗?
的HTML:
<div id="container">
<div class="color-me">Line 1</div>
<div class="color-me">Line 2</div>
</div>
Javascript:
var $divs = $('.color-me');
var $generatedDiv = $('<div></div>', {
'class': 'color-me',
'text': 'Line 3'
}).appendTo($('#container'));
$divs.pushStack($generatedDiv);
// Shouldn't the $generatedDiv be in the $divs jQuery stack now?
$divs.css('color', 'red');
jsFiddle:http: //jsfiddle.net/bGDxw/