2 text: function( text ) {
3 if ( typeof text !== "object" && text != null )
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 ] );
20 wrapAll: function( html ) {
22 // The elements to wrap the target around
23 var wrap = jQuery( html, this[0].ownerDocument ).clone();
25 if ( this[0].parentNode )
26 wrap.insertBefore( this[0] );
31 while ( elem.firstChild )
32 elem = elem.firstChild;
41 wrapInner: function( html ) {
42 return this.each(function(){
43 jQuery( this ).contents().wrapAll( html );
47 wrap: function( html ) {
48 return this.each(function(){
49 jQuery( this ).wrapAll( html );
54 return this.domManip(arguments, true, function(elem){
55 if (this.nodeType == 1)
56 this.appendChild( elem );
61 return this.domManip(arguments, true, function(elem){
62 if (this.nodeType == 1)
63 this.insertBefore( elem, this.firstChild );
68 return this.domManip(arguments, false, function(elem){
69 this.parentNode.insertBefore( elem, this );
74 return this.domManip(arguments, false, function(elem){
75 this.parentNode.insertBefore( elem, this.nextSibling );
79 clone: function( events ) {
81 var ret = this.map(function(){
82 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
83 // IE copies events bound via attachEvent when
84 // using cloneNode. Calling detachEvent on the
85 // clone will also remove the events from the orignal
86 // In order to get around this, we use innerHTML.
87 // Unfortunately, this means some modifications to
88 // attributes in IE that are actually only stored
89 // as properties will not be copied (such as the
90 // the name attribute on an input).
91 var html = this.outerHTML, ownerDocument = this.ownerDocument;
93 var div = ownerDocument.createElement("div");
94 div.appendChild( this.cloneNode(true) );
98 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")], ownerDocument)[0];
100 return this.cloneNode(true);
103 // Copy the events from the original to the clone
104 if ( events === true ) {
105 var orig = this.find("*").andSelf(), i = 0;
107 ret.find("*").andSelf().each(function(){
108 if ( this.nodeName !== orig[i].nodeName )
111 var events = jQuery.data( orig[i], "events" );
113 for ( var type in events ) {
114 for ( var handler in events[ type ] ) {
115 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
123 // Return the cloned set
127 html: function( value ) {
128 return value === undefined ?
130 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
132 this.empty().append( value );
135 replaceWith: function( value ) {
136 return this.after( value ).remove();
139 domManip: function( args, table, callback ) {
141 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
142 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
143 first = fragment.firstChild;
146 for ( var i = 0, l = this.length; i < l; i++ )
147 callback.call( root(this[i], first), this.length > 1 || i > 0 ?
148 fragment.cloneNode(true) : fragment );
151 jQuery.each( scripts, evalScript );
156 function root( elem, cur ) {
157 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
158 (elem.getElementsByTagName("tbody")[0] ||
159 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
167 prependTo: "prepend",
168 insertBefore: "before",
169 insertAfter: "after",
170 replaceAll: "replaceWith"
171 }, function(name, original){
172 jQuery.fn[ name ] = function( selector ) {
173 var ret = [], insert = jQuery( selector );
175 for ( var i = 0, l = insert.length; i < l; i++ ) {
176 var elems = (i > 0 ? this.clone(true) : this).get();
177 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
178 ret = ret.concat( elems );
181 return this.pushStack( ret, name, selector );
186 remove: function( selector ) {
187 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
188 if ( this.nodeType === 1 ) {
189 cleanData( jQuery("*", this).add(this) );
192 if ( this.parentNode ) {
193 this.parentNode.removeChild( this );
199 // Remove element nodes and prevent memory leaks
200 if ( this.nodeType === 1 ) {
201 cleanData( jQuery("*", this) );
204 // Remove any remaining nodes
205 while ( this.firstChild ) {
206 this.removeChild( this.firstChild );
209 }, function(name, fn){
210 jQuery.fn[ name ] = function(){
211 return this.each( fn, arguments );
216 clean: function( elems, context, fragment ) {
217 context = context || document;
219 // !context.createElement fails in IE with an error but returns typeof 'object'
220 if ( typeof context.createElement === "undefined" )
221 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
223 // If a single string is passed in and it's a single tag
224 // just do a createElement and skip the rest
225 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
226 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
228 return [ context.createElement( match[1] ) ];
231 var ret = [], scripts = [], div = context.createElement("div");
233 jQuery.each(elems, function(i, elem){
234 if ( typeof elem === "number" )
240 // Convert html string into DOM nodes
241 if ( typeof elem === "string" ) {
242 // Fix "XHTML"-style tags in all browsers
243 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
244 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
246 front + "></" + tag + ">";
249 // Trim whitespace, otherwise indexOf won't work as expected
250 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
253 // option or optgroup
254 !tags.indexOf("<opt") &&
255 [ 1, "<select multiple='multiple'>", "</select>" ] ||
257 !tags.indexOf("<leg") &&
258 [ 1, "<fieldset>", "</fieldset>" ] ||
260 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
261 [ 1, "<table>", "</table>" ] ||
263 !tags.indexOf("<tr") &&
264 [ 2, "<table><tbody>", "</tbody></table>" ] ||
266 // <thead> matched above
267 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
268 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
270 !tags.indexOf("<col") &&
271 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
273 // IE can't serialize <link> and <script> tags normally
274 !jQuery.support.htmlSerialize &&
275 [ 1, "div<div>", "</div>" ] ||
279 // Go to html and back, then peel off extra wrappers
280 div.innerHTML = wrap[1] + elem + wrap[2];
282 // Move to the right depth
286 // Remove IE's autoinserted <tbody> from table fragments
287 if ( !jQuery.support.tbody ) {
289 // String was a <table>, *may* have spurious <tbody>
290 var hasBody = /<tbody/i.test(elem),
291 tbody = !tags.indexOf("<table") && !hasBody ?
292 div.firstChild && div.firstChild.childNodes :
294 // String was a bare <thead> or <tfoot>
295 wrap[1] == "<table>" && !hasBody ?
299 for ( var j = tbody.length - 1; j >= 0 ; --j )
300 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
301 tbody[ j ].parentNode.removeChild( tbody[ j ] );
305 // IE completely kills leading whitespace when innerHTML is used
306 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
307 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
309 elem = jQuery.makeArray( div.childNodes );
315 ret = jQuery.merge( ret, elem );
320 for ( var i = 0; ret[i]; i++ ) {
321 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
322 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
324 if ( ret[i].nodeType === 1 )
325 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
326 fragment.appendChild( ret[i] );
337 function cleanData( elems ) {
338 for ( var i = 0, l = elems.length; i < l; i++ ) {
339 var id = elems[i][expando];
341 delete jQuery.cache[ id ];