简体   繁体   English

如何包装全部-OL元素转换为ahref元素

[英]How to wrapAll - ol element to ahref element

I would like to wrap the following code in a div with a jQuery wrap: 我想用jQuery wrap将以下代码包装在div中:

<ol class="pagination-links">
    <li>test</li>
    <li>test</li>
</ol>

<a class="prev" href="#">Prev</a>
<a class="next" href="#">Next</a>

Using the wrap function, I dont know how to call these elements. 使用wrap函数,我不知道如何调用这些元素。

<script type="text/javascript">
    $(function() {
        $('ol').each(function(i, e) {
            $(e).nextUntil('.next').wrapAll('<div>');
        });
    });
</script>

尝试这个:

$('ol.pagination-links, a.prev, a.next').wrapAll('<div>');

You could use a multiple selector - 您可以使用多个选择器-

$("ol.pagination-links,a.prev,a.next").wrapAll('<div>');

Demo - http://jsfiddle.net/jEkVC/ 演示-http://jsfiddle.net/jEkVC/

Try this: 尝试这个:

$(".pagination-links, a.prev, a.next").wrapAll('<div></div>');

Be aware though, because your are selecting by classes, if you have multiple instances of these elements on one page they will all be wrapped in 1 div, as opposed to each group of ol and 2x a elements per div 但是请注意,因为您是按类选择的,所以如果您在一页上具有这些元素的多个实例,它们将全部包装在1 div中,而不是每组ol和每div 2x a元素

Example fiddle 小提琴的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM