
The <img> element object splits the text into two text objects:
• the text before the
<img> element “The element can contain text and
other elements such as images”
• and the text after “or other.”
2. In general, to retrieve the text of an element, it is safer to iterate over
the element’s children. Fortunately, because
getText() is isolated in a
separate function, it’s easy to replace:
function getText(node)
{
if(node.nodeType == 1)
{
var text = “”,
children = node.childNodes,
i;
for(i = 0;i < children.length;i++)
if(children.item(i).nodeType == 3)
text += children.item(i).data;
return text
}
else
return “”;
}
Managing the State
The previous example is very simple. ...