Below is the output of alert( rd.innerHTML );
:
<ruby><rb>「わたし</rb><rt><br>watashi</rt></ruby><ruby><rb>は</rb><rt><br>wa</rt></ruby>」<Name des Sprechers><br><ruby><rb>です</rb><rt><br>desu</rt></ruby>。
I like to iterate over all those nodes. I tried (among others):
var items = rd.getElementsByTagName("*");
for (var i = 0; i < items.length; i++) {
var item = items[i];
alert( item.innerHTML);
}
But for the loop above I will get
<rb>「わたし</rb><rt><br>watashi</rt>
「わたし
n watashi
<rb>は</rb><rt><br>wa</rt>
は
n wa
<rb>です</rb><rt><br>desu</rt>
です
n desu
How can I loop this HTML and also get the node 」<Name des Sprechers><br>
Ideally I would like to have all rb
elements and the text node in this order:
<rb>「わたし</rb><rt><br>watashi</rt>
<rb>は</rb><rt><br>wa</rt>
」<Name des Sprechers><br>
<rb>です</rb><rt><br>desu</rt>
2
Answers
Where did
Sprechers
disappear in your output? Well you need to traverse thenodes
rather than theelements
. I’m re-using a function to extract text nodes from a node / element.I think this is kind of tricky question.
If my guess is rigth, you’re trying to separate japanese texts from ocidental ones…
Try the snippet below. All names are self explanatories.
NOTE: The function
separateLanguages
will only iterate over the root element, not its children.