javascript - Ways of setting/getting a textNode's value -


this question has answer here:

there many ways retrieve/change value of text node:

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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -