jquery,在div中包装一个元素 [英] jquery, wrap an element in a div

查看:51
本文介绍了jquery,在div中包装一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div id="top">

   <span id="innter"></span> Here may have a lot of different div, span


</div>

我想要做的是用另一个div元素包装span。

What I want to do is wrap the span by another div element.

所以看起来像这样:

<div id="top">
   <div id="wrapper">
       <span id="innter"></span>
    </div
</div>

最好的方法是什么?
我发现wrapAll()很有用,但不知道如何在#top中包含所有元素。

What is the best way to do this? I found wrapAll() is useful, but not sure how to include all the elements inside #top.

推荐答案

使用 .wrap()方法

$('#innter').wrap('<div id="wrapper" />');

这篇关于jquery,在div中包装一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆