简体   繁体   English

我可以获取HTMLElement DOM对象的完整HTML表示吗?

[英]Can I get the full HTML representation of an HTMLElement DOM object?

I'm using jquery to parse some HTML, something like: 我正在使用jquery解析一些HTML,例如:

$(html).contents().each(function(){
  var element = this.tagName;
  ...

I can access the tagName, children, parent... using the DOM or the more friendly jQuery functions. 我可以使用DOM或更友好的jQuery函数访问tagName,子级,父级...。

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). 但是有一点需要当前元素的整个HTML(而不是innerHTML.html()返回的内容),而且我无法找出一个衬板来获取它(我总是可以手动将标记和属性附加到innerHTML)。

For example: 例如:

<a href="link">Link</a>

The innerHTML is Link but I'm looking for the whole <a href="link">Link</a> innerHTMLLink但我正在寻找整个<a href="link">Link</a>

does that oneliner exists? 那班轮存在吗?

看起来这家伙使用jQuery有一个不错的解决方案: externalHTML

just saw the anwser for this on the other thread :D 刚刚在另一个线程上看到了anwser:D

outerHTML 外层HTML

outerHTML 2 externalHTML 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM