contents
doesn't take any arguments. This works even if you add more text after the a
.
$('article').each(function() {
var t = $(this).find('figure > figcaption').contents().filter(function() {
return this.nodeType === 3; //3 = TEXT_NODE
});
alert(t.text());
});
If you want every piece of text within figcaption
except the text in a
, use this:
return this.nodeType === 3 || this.tagName !== 'A';
Regarding the nodeType
property
<a id='a'>asdf</a>
var a = document.getElementById('a');
a.nodeType === Node.ELEMENT_NODE; //true
a.firstChild.nodeType == Node.TEXT_NODE; //true asdf