jQuery环绕文本 [英] jQuery wrap span around text
本文介绍了jQuery环绕文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下
<div><span class="myspan">hello</span> this text has no span </div>
在jQuery中,如何包装 div
或跨越此文本没有跨度文本?
In jQuery, how can I wrap a div
or span around the "this text has no span" text?
推荐答案
对于您当前的示例,这是我的一行解决方案:
For your current example here is my one line solution:
$("div span").detach().prependTo($("div").contents().wrap("<span />").end());
DEMO: http://jsfiddle.net/awwTA/
这篇关于jQuery环绕文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文