Bohdan
Bohdan

Reputation: 8408

how to get part of html in javascript?

    All I want to get only "All" without <ins>

When I use $j(this).parent().html() I get

<ins class="jstree-checkbox">&nbsp;</ins>
<ins class="jstree-icon">&nbsp;</ins>
All

but I need only "All" How can I get it ?

Upvotes: 2

Views: 360

Answers (3)

Andreas
Andreas

Reputation: 5335

Try the following to get 'All'

obj = $(this).parent().get(0); 
var allText = obj.lastChild.nodeValue;

Upvotes: 2

Bohdan
Bohdan

Reputation: 8408

($j(this).parent().html().substring(78, $j(this).parent().html().length)

Any better solutions ?

Upvotes: 1

user113716
user113716

Reputation: 322452

Assuming the .parent() part is correct, try this:

var result = $j(this).parent().contents().last().text();

You may want to trim the result, because there will likely be white space.

var result = $j(this).parent().contents().last().text();

result = $j.trim(result);

Or if there isn't any other text, you can just do this:

var result = $j(this).parent().text();

Upvotes: 4

Related Questions