XML DOM textContent attribute
Definition and usage
The textContent attribute sets or returns the text content of the attribute.
Syntax:
attrObject.textContent
Instance
In all examples, we will use the XML file books.xml, as well as the JavaScript function loadXMLDoc().
The following code snippet returns the text content of the category attribute:
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].textContent
);
document.write("<br />");
}
The output of the above code is:
children cooking web web
TIY
- textContent - Get the text content of the attribute(Not supported by IE browser)
- textContent - Set the text content of the attribute(Not supported by IE browser)