File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed
Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -31,19 +31,21 @@ if ( !jQuery.support.htmlSerialize ) {
3131
3232jQuery . fn . extend ( {
3333 text : function ( text ) {
34- if ( typeof text !== "object" && text !== undefined )
34+ if ( typeof text !== "object" && text !== undefined ) {
3535 return this . empty ( ) . append ( ( this [ 0 ] && this [ 0 ] . ownerDocument || document ) . createTextNode ( text ) ) ;
36+ }
3637
3738 var ret = "" ;
3839
39- jQuery . each ( text || this , function ( ) {
40- jQuery . each ( this . childNodes , function ( ) {
41- if ( this . nodeType !== 8 ) {
42- ret += this . nodeType !== 1 ?
43- this . nodeValue :
44- jQuery . fn . text ( [ this ] ) ;
45- }
46- } ) ;
40+ jQuery . each ( this , function ( ) {
41+ // Get the text from text nodes and CDATA nodes
42+ if ( this . nodeType === 3 || this . nodeType === 4 ) {
43+ ret += this . nodeValue ;
44+
45+ // Traverse everything else, except comment nodes
46+ } else if ( this . nodeType !== 8 ) {
47+ ret += jQuery . fn . text . call ( this . childNodes ) ;
48+ }
4749 } ) ;
4850
4951 return ret ;
Original file line number Diff line number Diff line change @@ -4,9 +4,12 @@ var bareObj = function(value) { return value; };
44var functionReturningObj = function ( value ) { return ( function ( ) { return value ; } ) ; } ;
55
66test ( "text()" , function ( ) {
7- expect ( 1 ) ;
7+ expect ( 2 ) ;
88 var expected = "This link has class=\"blog\": Simon Willison's Weblog" ;
99 equals ( jQuery ( '#sap' ) . text ( ) , expected , 'Check for merged text of more then one element.' ) ;
10+
11+ // Check serialization of text values
12+ equals ( jQuery ( document . createTextNode ( "foo" ) ) . text ( ) , "foo" , "Text node was retreived from .text()." ) ;
1013} ) ;
1114
1215var testWrap = function ( val ) {
You can’t perform that action at this time.
0 commit comments