I found How do I select text nodes with jQuery? but my problem is that although I can go like
$(elem)
.contents()
.filter(function() {
return this.nodeType == Node.TEXT_NODE;
}).each(function() {
this.nodeValue = //stuff
});
I am trying to figure out how I can combine this.nodeType with the before and after nodes because some of the stuff I need can appear as a combination of the this.nodeValue + before, this.nodeValue or this.nodeValue + after if that makes sense and I need to test EACH node value as well as it in combination with the previous and next ?
If I understood correctly, you wanted to get the
prevand nextnodewhen you hit the text node. See below,DEMO: http://jsfiddle.net/SFmRR/
Note: In the demo, the elements inside div doesn’t have any additional space/line breaks because when you iterate over
contents()It includes line breaks and space as textNode.