JQuery:选择一个元素的html,包括? [英] JQuery: Select html of an element, inclusive?
本文介绍了JQuery:选择一个元素的html,包括?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择元素的html的最佳方式是什么?例如:
What's the best way to select the html of an element, inclusive? For example:
<div id="testDiv" class="testClass">
This is just a test.
</div>
而 $('#testDiv')。html c $ c>返回
这只是一个测试。
,我将一个选择器返回:
Whereas $('#testDiv').html()
returns "This is just a test."
, I would a selector that returns:
code>< div id =testDivclass =testClass>这只是一个测试。< / div> 。
<div id="testDiv" class="testClass">This is just a test.</div>
.
感谢您的回复。
推荐答案
尝试 this jQuery.outerHTML()
implementation 。
Try this jQuery.outerHTML()
implementation.
jQuery.fn.outerHTML = function() {
return $('<div>').append( this.eq(0).clone() ).html();
};
这篇关于JQuery:选择一个元素的html,包括?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文