aboutsummaryrefslogtreecommitdiffstats
path: root/src/manipulation.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-11-17 14:52:08 -0500
committerJohn Resig <jeresig@gmail.com>2009-11-17 14:52:08 -0500
commitb30af34f28074b491929445f5aad3d62c63e772f (patch)
treef58d797f8a4021d16c991c8a54dbbb2f2047f3c6 /src/manipulation.js
parentc08474580caa44d2b5f32be54c0d884832bbd1c3 (diff)
downloadjquery-b30af34f28074b491929445f5aad3d62c63e772f.tar.gz
jquery-b30af34f28074b491929445f5aad3d62c63e772f.zip
Added support for .text() on text nodes. Fixes #5525.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r--src/manipulation.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 1699f6801..2a6b9dc30 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -31,19 +31,21 @@ if ( !jQuery.support.htmlSerialize ) {
jQuery.fn.extend({
text: function( text ) {
- if ( typeof text !== "object" && text !== undefined )
+ if ( typeof text !== "object" && text !== undefined ) {
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
+ }
var ret = "";
- jQuery.each( text || this, function(){
- jQuery.each( this.childNodes, function(){
- if ( this.nodeType !== 8 ) {
- ret += this.nodeType !== 1 ?
- this.nodeValue :
- jQuery.fn.text( [ this ] );
- }
- });
+ jQuery.each( this, function() {
+ // Get the text from text nodes and CDATA nodes
+ if ( this.nodeType === 3 || this.nodeType === 4 ) {
+ ret += this.nodeValue;
+
+ // Traverse everything else, except comment nodes
+ } else if ( this.nodeType !== 8 ) {
+ ret += jQuery.fn.text.call( this.childNodes );
+ }
});
return ret;