given the html:
<div>
<span class="a">a
<span class="b">b</span>
</span>
<div>
Is it possible to just select the first span and not it's children?
Calling $('div span.a').text() prints the 'b' in the child node as well as the 'a'
given the html:
<div>
<span class="a">a
<span class="b">b</span>
</span>
<div>
Is it possible to just select the first span and not it's children?
Calling $('div span.a').text() prints the 'b' in the child node as well as the 'a'
var span1 = $("span.a").clone();
$(span1).children().remove();
var text = $(span1).text();
You probably would be better off writing better structured html like:
<div>
<span class="c">
<span class="a">a</span>
<span class="b">b</span>
</span>
</div>
But you could do this:
var text = $('div span.a').clone().find('*').remove().end().text();