可以获得HTMLElment DOM对象的完整HTML代表吗? [英] Can I get the full HTML represenation of an HTMLElment DOM object?

查看:101
本文介绍了可以获得HTMLElment DOM对象的完整HTML代表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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() return),我无法找出一个班轮得到它(我总是可以将标签和属性手动附加到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> Link< / a>

The innerHTML is Link but I'm looking for the whole <a href="link">Link</a>

是否存在oneliner?

does that oneliner exists?

谢谢。

推荐答案

看起来这个人有一个非常漂亮的solutio n使用jQuery: outerHTML

Looks like this guy has a pretty nifty solution using jQuery: outerHTML

这篇关于可以获得HTMLElment DOM对象的完整HTML代表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆