javascript - Ways of setting/getting a textNode's value -
this question has answer here:
- how retrieve text of dom text node? 3 answers
there many ways retrieve/change value of text node:
- it's not
textnode.value, xul-only thing textcontent[mdn] not supported until ie9data, inheritedtextcharacterdatainterfacenodevalue[mdn]nodeinterface
i tend use .data. of them recommended - return same?
if have text_node [type 3] textcontent return nodevalue (mdn):
if node cdata section, comment, processing instruction, or text node, textcontent returns text inside node (the nodevalue).
characterdata same nodevalue text nodes (mdn).
text, comment, , cdatasection implement characterdata, in turn implements node.
for text nodes same.
jquery (sizzle) uses nodevalue:
/** * utility function retreiving text value of array of dom nodes * @param {array|element} elem */ var gettext = sizzle.gettext = function( elem ) { ... if ( nodetype === 1 || nodetype === 9 || nodetype === 11 ) { // use textcontent || innertext elements if ( typeof elem.textcontent === 'string' ) { return elem.textcontent; } else if ( typeof elem.innertext === 'string' ) { // replace ie's carriage returns return elem.innertext.replace( rreturn, '' ); } ... // text_node } else if ( nodetype === 3 || nodetype === 4 ) { return elem.nodevalue; } return ret; }; so using data fine, textcontent ie9+ , bit slower.
Comments
Post a Comment