Sorry, if the title is too obscure ;D.
Actually the problem is, lets say i am this code.
This will create a new div
and append a clone of your element to that div
. The new div
never gets inserted into the DOM, so it doesn't affect your page.
var theResult = $('').append($("#spanIDxx").clone()).html();
alert( theResult );
If you need to use this frequently, and don't want to bother with adding yet another plugin, just make it into a function:
function htmlInclusive(elem) { return $('').append($(elem).clone()).html(); }
alert( htmlInclusive("#spanIDxx") );
Or extend jQuery yourself:
$.fn.htmlInclusive = function() { return $('').append($(this).clone()).html(); }
alert( $("#spanIDxx").htmlInclusive() );