jQuery:外部html() [英] jQuery: outer html()
本文介绍了jQuery:外部html()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
获取所选元素的外部HTML
Possible Duplicate:
Get selected element’s outer HTML
想象一下我们有这样的东西:
imagine what we have something like this:
<div id="xxx"><p>Hello World</p></div>
如果我们以这种方式调用.html函数:
if we call .html function in this way:
$("#xxx").html();
我们将得到:
<p>Hello World</p>
但是我需要得到:
<div id="xxx"><p>Hello World</p></div>
那么,我需要做什么?我想在#xxx周围添加另一个包装器,但这不是一个好主意.
So, what i need to do? I think to add another wrapper around #xxx, but this is not a good idea.
推荐答案
创建一个临时元素,然后创建clone()
和append()
:
Create a temporary element, then clone()
and append()
:
$('<div>').append($('#xxx').clone()).html();
这篇关于jQuery:外部html()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文