I’m trying to parse some of html where there is are repeating lines of code such as:
<a>This is <span>some text</span> but its <span>not grabbing the span</span> content</a>
So I am looping through the object and extracting this:
object.a[i].text();
but its only returning
"This is but its content"
How do I grab the text within the children nodes as well, all as one string?
Cheers
I don’t know E4X, but may I assume pure JavaScript is alright?
textContentdoesn’t seem to have great compatibility for IE prior to version 9. This works whentextContentis available. However I do not have IE8 so I cannot test with it, but this should work as well.That works in a client side implementation, but since it’s not working in your implementation I guess you’re going to need something more specific to your setup; unfortunately there’s not much I can do there. I will however give one more pure JS stab at it. This iterates through each child node of object.a[i], determines if it is a textNode or elementNode and pulls data or innerHTML respectively.
I’ll leave the jQuery version:
.contents: