2 text: function( text ) {
3 if ( typeof text !== "object" && text !== undefined )
4 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
8 jQuery.each( text || this, function(){
9 jQuery.each( this.childNodes, function(){
10 if ( this.nodeType !== 8 ) {
11 ret += this.nodeType !== 1 ?
13 jQuery.fn.text( [ this ] );
21 wrapAll: function( html ) {
22 if ( jQuery.isFunction( html ) ) {
23 return this.each(function() {
24 jQuery(this).wrapAll( html.apply(this, arguments) );
29 // The elements to wrap the target around
30 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone();
32 if ( this[0].parentNode ) {
33 wrap.insertBefore( this[0] );
39 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
40 elem = elem.firstChild;
50 wrapInner: function( html ) {
51 return this.each(function(){
52 jQuery( this ).contents().wrapAll( html );
56 wrap: function( html ) {
57 return this.each(function(){
58 jQuery( this ).wrapAll( html );
63 return this.domManip(arguments, true, function(elem){
64 if ( this.nodeType === 1 ) {
65 this.appendChild( elem );
71 return this.domManip(arguments, true, function(elem){
72 if ( this.nodeType === 1 ) {
73 this.insertBefore( elem, this.firstChild );
79 return this.domManip(arguments, false, function(elem){
80 this.parentNode.insertBefore( elem, this );
85 return this.domManip(arguments, false, function(elem){
86 this.parentNode.insertBefore( elem, this.nextSibling );
90 clone: function( events ) {
92 var ret = this.map(function(){
93 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
94 // IE copies events bound via attachEvent when
95 // using cloneNode. Calling detachEvent on the
96 // clone will also remove the events from the orignal
97 // In order to get around this, we use innerHTML.
98 // Unfortunately, this means some modifications to
99 // attributes in IE that are actually only stored
100 // as properties will not be copied (such as the
101 // the name attribute on an input).
102 var html = this.outerHTML, ownerDocument = this.ownerDocument;
104 var div = ownerDocument.createElement("div");
105 div.appendChild( this.cloneNode(true) );
106 html = div.innerHTML;
109 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")], ownerDocument)[0];
111 return this.cloneNode(true);
114 // Copy the events from the original to the clone
115 if ( events === true ) {
116 var orig = this.find("*").andSelf(), i = 0;
118 ret.find("*").andSelf().each(function(){
119 if ( this.nodeName !== orig[i].nodeName ) { return; }
121 var events = jQuery.data( orig[i], "events" );
123 for ( var type in events ) {
124 for ( var handler in events[ type ] ) {
125 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
133 // Return the cloned set
137 html: function( value ) {
138 return value === undefined ?
140 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
142 this.empty().append( value );
145 replaceWith: function( value ) {
146 return this.after( value ).remove();
149 domManip: function( args, table, callback ) {
150 var fragment, scripts, cacheable, cached, cacheresults, first,
153 if ( jQuery.isFunction(value) ) {
154 return this.each(function() {
155 args[0] = value.call(this);
156 return jQuery(this).domManip( args, table, callback );
161 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("<option") < 0 ) {
163 cacheresults = jQuery.fragments[ args[0] ];
164 if ( cacheresults ) {
165 if ( cacheresults !== 1 ) {
166 fragment = cacheresults;
173 fragment = (this[0].ownerDocument || this[0]).createDocumentFragment();
174 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment );
177 first = fragment.firstChild;
180 table = table && jQuery.nodeName( first, "tr" );
182 for ( var i = 0, l = this.length; i < l; i++ ) {
185 root(this[i], first) :
187 cacheable || this.length > 1 || i > 0 ?
188 fragment.cloneNode(true) :
195 jQuery.each( scripts, evalScript );
199 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
205 function root( elem, cur ) {
206 return jQuery.nodeName(elem, "table") ?
207 (elem.getElementsByTagName("tbody")[0] ||
208 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
214 jQuery.fragments = {};
218 prependTo: "prepend",
219 insertBefore: "before",
220 insertAfter: "after",
221 replaceAll: "replaceWith"
222 }, function(name, original){
223 jQuery.fn[ name ] = function( selector ) {
224 var ret = [], insert = jQuery( selector );
226 for ( var i = 0, l = insert.length; i < l; i++ ) {
227 var elems = (i > 0 ? this.clone(true) : this).get();
228 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
229 ret = ret.concat( elems );
232 return this.pushStack( ret, name, selector );
237 remove: function( selector ) {
238 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
239 if ( this.nodeType === 1 ) {
240 cleanData( jQuery("*", this).add(this) );
243 if ( this.parentNode ) {
244 this.parentNode.removeChild( this );
250 // Remove element nodes and prevent memory leaks
251 if ( this.nodeType === 1 ) {
252 cleanData( jQuery("*", this) );
255 // Remove any remaining nodes
256 while ( this.firstChild ) {
257 this.removeChild( this.firstChild );
260 }, function(name, fn){
261 jQuery.fn[ name ] = function(){
262 return this.each( fn, arguments );
267 clean: function( elems, context, fragment ) {
268 context = context || document;
270 // !context.createElement fails in IE with an error but returns typeof 'object'
271 if ( typeof context.createElement === "undefined" ) {
272 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
275 // If a single string is passed in and it's a single tag
276 // just do a createElement and skip the rest
277 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
278 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
280 return [ context.createElement( match[1] ) ];
283 var ret = [], scripts = [], div = context.createElement("div");
285 jQuery.each(elems, function(i, elem){
286 if ( typeof elem === "number" ) {
290 if ( !elem ) { return; }
292 // Convert html string into DOM nodes
293 if ( typeof elem === "string" ) {
294 // Fix "XHTML"-style tags in all browsers
295 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
296 return /^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i.test(tag) ?
298 front + "></" + tag + ">";
301 // Trim whitespace, otherwise indexOf won't work as expected
302 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
305 // option or optgroup
306 !tags.indexOf("<opt") &&
307 [ 1, "<select multiple='multiple'>", "</select>" ] ||
309 !tags.indexOf("<leg") &&
310 [ 1, "<fieldset>", "</fieldset>" ] ||
312 /^<(thead|tbody|tfoot|colg|cap)/.test(tags) &&
313 [ 1, "<table>", "</table>" ] ||
315 !tags.indexOf("<tr") &&
316 [ 2, "<table><tbody>", "</tbody></table>" ] ||
318 // <thead> matched above
319 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
320 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
322 !tags.indexOf("<col") &&
323 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
325 // IE can't serialize <link> and <script> tags normally
326 !jQuery.support.htmlSerialize &&
327 [ 1, "div<div>", "</div>" ] ||
331 // Go to html and back, then peel off extra wrappers
332 div.innerHTML = wrap[1] + elem + wrap[2];
334 // Move to the right depth
335 while ( wrap[0]-- ) {
339 // Remove IE's autoinserted <tbody> from table fragments
340 if ( !jQuery.support.tbody ) {
342 // String was a <table>, *may* have spurious <tbody>
343 var hasBody = /<tbody/i.test(elem),
344 tbody = !tags.indexOf("<table") && !hasBody ?
345 div.firstChild && div.firstChild.childNodes :
347 // String was a bare <thead> or <tfoot>
348 wrap[1] == "<table>" && !hasBody ?
352 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
353 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
354 tbody[ j ].parentNode.removeChild( tbody[ j ] );
360 // IE completely kills leading whitespace when innerHTML is used
361 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) ) {
362 div.insertBefore( context.createTextNode( /^\s*/.exec(elem)[0] ), div.firstChild );
365 elem = jQuery.makeArray( div.childNodes );
368 if ( elem.nodeType ) {
371 ret = jQuery.merge( ret, elem );
377 for ( var i = 0; ret[i]; i++ ) {
378 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
379 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
381 if ( ret[i].nodeType === 1 )
382 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
383 fragment.appendChild( ret[i] );
394 function cleanData( elems ) {
395 for ( var i = 0, l = elems.length; i < l; i++ ) {
396 var id = elems[i][expando];
398 delete jQuery.cache[ id ];