No, if, no else Javascript? Look here.
Update 10-OCT-2017: This little plugin is consistently on the top of most viewed ones on this site. Let’s see why.
There are several outerHTML plugins for jQuery around. But I could not find any that works “in the spirit of jQuery”.
Side note: Have you seen this plugin ? It gives you list of events attached. Check it out later.
Update 13-NOV-2015
After reading recently the 2 year old post on stackoverflow.com, from where a lot of people are coming here, I have decided, to behave responsibly, and offer an (slightly) more optimized version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* (c) DBJ.ORG, GPL Licence applies Slightly better version of "my" outerHTL jQuery plugin. It is optimized to use outerHTML; if one is found. */ jQuery.fn.outerHTML = /* is there a native outerHTML ? */ !! document.body.outerHTML /* yes there is, so use it */ ? function( ) { var r = "" ; this.each(function () { r += this.outerHTML ; }) ; return r; } /* no there is not, so we shall use jQuery */ : function( ) { return $("<div></div>").append( this.clone() ).html(); }; /* (c) DBJ.ORG, GPL Licence applies */ |
Is this an optimization or obfuscation? To actually prove if this is better version performance wise, I should test it.
Continue reading