Jquery 在元素中包装文本

Jquery 在元素中包装文本,jquery,jstree,Jquery,Jstree,我正在使用jquery插件,它在树中生成这样的链接 <a href="#" class=""><ins class="jstree-icon" style="background: url("images/icon.png") no-repeat scroll center center transparent;">&nbsp;</ins>some lo

我正在使用jquery插件,它在树中生成这样的链接

<a href="#" class=""><ins class="jstree-icon" style="background: url("images/icon.png") no-repeat scroll center center transparent;">&nbsp;</ins>some long text</a>

现在我想将文本包装在一个范围内,因为我想使用jquery插件。我怎样才能以最简单的方式做到这一点?ins元素当然必须在跨度之外。我尝试使用wrap/wrapInner jquery函数,但它也总是将ins元素包装起来

当节点创建时,是否可以访问jsTree事件?它是哪一个?

var text=$(“a”).contents().filter(function()){
var text = $("a").contents().filter(function() {
  return this.nodeType == 3;
});
$(text).wrap("<span />");
返回this.nodeType==3; }); $(文本)。换行(“”);

对jsTree一无所知,所以无法回答第二个问题。

一旦呈现了树视图,您可以调用下面的方法,其中“test”将是锚的类名

$(function() {
    $('a.test').each(function() {
        var ins = $(this).find('ins');
        var span = $('<span class="new" />');
        span.text($(this).text());
        $(this).html('');
        $(this).append(ins);
        $(this).append(span);
    });
});
$(函数(){
$('a.test')。每个(函数(){
var ins=$(this.find('ins');
变量范围=$('');
text($(this.text());
$(this.html(“”);
$(此).append(ins);
$(this).append(span);
});
});

在此之后,您可以使用类“new”调用ThreeDots插件方法。

我给出了自己的答案

$('#id ul li a').each(function(){
var ins=$(this).find('ins').clone();
$(this).wrapInner('<span></span>').find('ins').remove();
$(this).find('span').before(ins);
});
$('id ul li a')。每个(函数(){
var ins=$(this.find('ins').clone();
$(this.wrapInner(“”).find('ins').remove();
$(this.find('span')。在(ins)之前;
});
但最简单的imo是带过滤器的答案。所以+1