jQuery: second detach ignored automatically?
Should i make such check, before detaching?
if(for_detach.parent().length) {for_detach.detach();}
开发者_C百科
or jquery automatically do it?
Thanks ;)
Update
Same with wr.find('iframe:hidden').show();
and different others situations.
You can always have a look at the source code.
In case of detach
:
detach: function( selector ) {
return this.remove( selector, true );
},
// keepData is for internal use only--do not document
remove: function( selector, keepData ) {
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
if ( !keepData && elem.nodeType === 1 ) {
jQuery.cleanData( elem.getElementsByTagName("*") );
jQuery.cleanData( [ elem ] );
}
if ( elem.parentNode ) {
elem.parentNode.removeChild( elem );
}
}
}
return this;
},
So yes, jQuery will make sure that there is a parent before it detaches from it, but it does not ignore the call.
It depends on the function whether calling it twice has any effect.
Of course if you call show
twice then the second call will not have any (visible) effect. But that does not mean that jQuery is not doing anything in the back. Have a look at the show
implementation.
精彩评论