我在我的 javascript 中尝试了这个,它不需要额外的插件就可以工作
var2 = $('.my_div')[0].outerHTML;
但是我在官方文档中找不到它。我在哪里可以找到更多相关信息
最佳答案
<强> outerHTML
是原生 JavaScript DOM 对象属性。您可以在 MDN 中阅读相关内容:
https://developer.mozilla.org/en-US/docs/DOM/element.outerHTML
The outerHTML attribute of the element DOM interface gets the serialized HTML fragment describing the element including its descendants. It can be set to replace the element with nodes parsed from the given string.
让 $('.my_div')[0]
成为您 get 来自 jQuery 对象的 DOM 对象。
关于javascript - 哪个jquery版本存在outerHTML方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12815412/