我尝试了Wrap
和WrapALl
以及nextUntil
,但这个非常棘手。我有这个HTML
<ul class="quick-list quick-glance hideOnSearch show-for-medium-up">
<li><span class="strong">Price:</span> $198000</li>
<li><span class="strong">Miles:</span> 349999</li>
<li><span class="strong">Vehicle Type:</span> Minivans and Vans</li>
</ul>
我希望它看起来像
<ul class="accordion show-for-small hide-for-medium-up">
<li>
<div class="title">TITLE</div>
<div class="content">
<ul class="quick-list quick-glance hideOnSearch show-for-medium-up">
<li><span class="strong">Price:</span> $198000</li>
<li><span class="strong">Miles:</span> 349999</li>
<li><span class="strong">Vehicle Type:</span> Minivans and Vans</li>
</ul>
</div>
</li>
</ul>
我试过这个
$('ul.quick-list').wrapAll('<ul class="accordion"><li><div class="title">TITLE</div><div class="content"></div></li></ul>'); //Single page Top accordion
但它将quick-list
置于错误的位置。
我如何使用jQuery做到这一点?
答案 0 :(得分:1)
wrapAll()只支持一个内部元素,你有两个。解决方案:
$('ul.quick-list').wrap('<ul class="accordion"><li><div class="content"></div></li></ul>');
$('.content').before('<div class="title">TITLE</div>');
答案 1 :(得分:0)
试试 DEMO
$(function(){
$('ul.quick-list').wrap('<ul class="accordion show-for-small hide-for-medium-up">').wrap("<li>").wrap('<div class="content">');
$('.content').before('<div class="title">TITLE</div>');
});