Permalink
Browse files

Native .outerHTML property will be used if it exists, div is only cre…

…ated if/when necessary and is now cached.
  • Loading branch information...
cowboy authored and brandonaaron committed Jun 25, 2010
1 parent 6e87231 commit cd2bca0d67d11358e5e02089028223637246e4b2
Showing with 12 additions and 5 deletions.
  1. +12 −5 jquery.outerhtml.js
View
@@ -3,9 +3,16 @@
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*/
(function($) {
// Returns whether or not a result set has results in it
$.fn.outerHTML = function() {
return $('<div>').append( this.eq(0).clone() ).html();
};
(function($){
var div;
$.fn.outerHTML = function() {
var elem = this[0],
tmp;
return !elem ? null
: typeof ( tmp = elem.outerHTML ) === 'string' ? tmp
: ( div = div || $('<div/>') ).html( this.eq(0).clone() ).html();

This comment has been minimized.

Show comment
Hide comment
@shesek

shesek Jul 21, 2011

Why was append() changed to html()? I assume append() should be faster, as the browser doesn't need to re-parse the HTML into DOM?

@shesek

shesek Jul 21, 2011

Why was append() changed to html()? I assume append() should be faster, as the browser doesn't need to re-parse the HTML into DOM?

};
})(jQuery);

2 comments on commit cd2bca0

@txdv

This comment has been minimized.

Show comment
Hide comment
@txdv

txdv Nov 17, 2010

what is this about ( bla == bla2 ), why the additional spaces?

txdv replied Nov 17, 2010

what is this about ( bla == bla2 ), why the additional spaces?

@brandonaaron

This comment has been minimized.

Show comment
Hide comment
@brandonaaron

brandonaaron Nov 17, 2010

Owner

Just a style preference. Check the jQuery Core Style Guidelines for more fun stylistic preferences. http://docs.jquery.com/JQuery_Core_Style_Guidelines#Spacing

Owner

brandonaaron replied Nov 17, 2010

Just a style preference. Check the jQuery Core Style Guidelines for more fun stylistic preferences. http://docs.jquery.com/JQuery_Core_Style_Guidelines#Spacing

Please sign in to comment.