jQuery.html() gets inner html. but i need the entire html [duplicate]
if i call
jquery("a").html()
i get what is INSIDE of the "a" tag
if i want the entire html, what do i call?
开发者_如何学C<a>xxxx</a>
jQuery.fn.outerHTML = function() {
return jQuery('<div />').append(this.eq(0).clone()).html();
}
jQuery('a').outerHTML(); // <a>xxxx</a>
What you want is outerHTML and there is no direct way to get that in jQuery. You can write your own function
jQuery.fn.outerHTML = function() {
return $('<div>').append( this.eq(0).clone() ).html();
};
$("yourselector").outerHTML();
In javascript you can use outerHTML, but isn't compatible with every browser. Take a loot at outerHTML
Check out the jQuery .outerHTML() plug-in from http://darlesson.com/jquery/outerhtml/. To get your HTML from the matched element you need something like:
$("a").outerHTML();
精彩评论