> BB, the contents() get all childNodes... through it, we can get the
> html code? how?
>
> I think in create a new div, insert the element in it, and get the
> innerHTML or html() of the div...
Yeah, that works:
jQuery.fn.elementHTML = function(){
var $nodes = jQuery("<div></div>");
this.each(function(){
$nodes.append(this.cloneNode(false));
});
return $nodes.html();
};
Note that it does *not* return text nodes within the elements, since
they too are child nodes. I would be interested to know what you are
doing with this, because I could not think of a good situation where
it might be used.