如何获取“#container”上的 html,包括“#container”,而不仅仅是其中的内容。
<div id="container">
<div id="one">test 1 </div>
<div id="two">test 2 </div>
<div id="three">test 3 </div>
<div id="four">test 4 </div>
</div>
我有这个可以在#container 中获取 html。它不包括#container 元素本身。这就是我想做的事情
var x = $('#container').html();
$('#save').val(x);
最佳答案
如果你将容器包裹在一个假人 P
标记您还将获得容器 HTML。
你需要做的就是
var x = $('#container').wrap('<p/>').parent().html();
查看 http://jsfiddle.net/rzfPP/68/ 上的工作示例
致unwrap()
<p>
标签完成后,您可以添加
$('#container').unwrap();
关于javascript - jQuery获取容器的html,包括容器本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6459398/