lkurylo
lkurylo

Reputation: 1651

wraping text in element

I'm using the jsTree jquery plugin which produces the links in the tree like that

<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>

Now I want to wrap the text in a span, because I want to use the ThreeDots jquery plugin. How can I do that in the easiest way? The ins element of course must be outside the span. I tried to use the wrap/wrapInner jquery functions but it always wrapping me the ins element too.

Is it possible to get access to the jsTree event, when the nodes are creating? Which one is it?

Upvotes: 1

Views: 501

Answers (3)

lkurylo
lkurylo

Reputation: 1651

I come up with my own answer

$('#id ul li a').each(function(){
var ins=$(this).find('ins').clone();
$(this).wrapInner('<span></span>').find('ins').remove();
$(this).find('span').before(ins);
});

but the easiest imo is the answer with filter. So +1.

Upvotes: 0

kvc
kvc

Reputation: 1137

Once your tree view is rendered you can call the below method,where 'test' would be the class name for your anchors.

$(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);
    });
});

After this you can call the ThreeDots plugin method with the class "new"

Upvotes: 1

Fenec
Fenec

Reputation: 1222

var text = $("a").contents().filter(function() {
  return this.nodeType == 3;
});
$(text).wrap("<span />");

Don't know anything about jsTree so can't answer second question.

Upvotes: 1

Related Questions