开发者

jQuery.html() gets inner html. but i need the entire html [duplicate]

This question already has answers here: Get selected element's outer HTML (30 answers) Closed 7 years ago.

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜