我可以获得HTMLElement DOM对象的完整HTML表示吗? [英] Can I get the full HTML representation of an HTMLElement DOM object?
问题描述
我正在使用jquery来解析一些HTML,例如:
I'm using jquery to parse some HTML, something like:
$(html).contents().each(function(){
var element = this.tagName;
...
我可以使用DOM或更友好的jQuery函数访问tagName,children,parent ...。
I can access the tagName, children, parent... using the DOM or the more friendly jQuery functions.
但是有一点需要整个HTML的当前元素(不是 innerHTML
或 .html()
返回)我无法想出一个单行得到它(我总是可以手动将标签和属性附加到innerHTML)。
But at one point a need the whole HTML of the current element (not what innerHTML
or .html()
return) and I can't figure out a one liner to get it (I always could attach the tag and the attributes manually to the innerHTML).
例如:
<a href="link">Link</a>
innerHTML
是链接
但我正在寻找整个< a href =link>链接< / a>
The innerHTML
is Link
but I'm looking for the whole <a href="link">Link</a>
该oneliner是否存在?
does that oneliner exists?
推荐答案
看起来这个家伙使用jQuery有一个非常漂亮的解决方案: outerHTML
Looks like this guy has a pretty nifty solution using jQuery: outerHTML
这篇关于我可以获得HTMLElement DOM对象的完整HTML表示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!