开发者

How to get html of matched element in jquery

I have this html

<div id"test123">
dasd'asdasd

</div>

I want the content of that div box with "<div i开发者_StackOverflow中文版d="test123">" itself as well not just innerhtml

I tried $('#test123').html()

But it only gave me inner html


Another alternative, which looks more linear/nicer to me:

var html = $('#foo').wrap('<div/>').parent().html();
$('#foo').unwrap();
found here:
http://codeasp.net/blogs/raghav_khunger/microsoft-net/751/jquery-how-to-get-html-of-a-div-with-that-div-tag-included


Doesn't seem to be an easy way in the box.

http://brandonaaron.net/blog/2007/06/17/jquery-snippets-outerhtml/


var div = $('#test123').eq(0);
console.log(div);


Pretty gnarly, but it gets the job done:

$('<div />').append($('#test123').clone()).html();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜