views:

62

answers:

3

Hi I have next

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

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 ?

+3  A: 

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();
patrick dw
Works with a tweak: `var result = $j(this).parent().contents().last().text();` (http://jsfiddle.net/krLw3/)
Pat
You're right, it works fine
Bohdan Pohorilets
@Pat - Thanks. :o) I caught that before my last edit. In my test code I had `.text()` on the next line.
patrick dw
A: 
($j(this).parent().html().substring(78, $j(this).parent().html().length)

Any better solutions ?

Bohdan Pohorilets
+1  A: 

Try the following to get 'All'

obj = $(this).parent().get(0); 
var allText = obj.lastChild.nodeValue;
andreas
andreas - Good solution. Although if you're going to take the native API route, might as well go all the way: `var allText = this.parentNode.lastChild.nodeValue;` :o)
patrick dw
i admit it...it's a 'hybrid' :) Good point there Patrick
andreas