jquery outerhtml

jquery outerhtmljqueryouterhtml 让Firefox支持outerHTML(使用jQuery1.3)Postedon2009-06-1617:43吕霖阅读(627)评论(7)编辑收藏1、今天获取元素的html,而firefox却不支持如下代码…

大家好,又见面了,我是你们的朋友全栈君。

让 Firefox 支持 outerHTML (使用jQuery1.3)

Posted on 2009-06-16 17:43 
吕霖 阅读(627) 
评论(7) 
编辑 
收藏 
jquery outerhtml

1、今天获取元素的html,而firefox却不支持如下代码

var elemstr = $(“#” + name)[0].outerHTML;

2、看到网上很多文章讨论Firefox如何使用outerHTML,给出的解决方案都颇为复杂。

如果使用jQuery1.3,则问题变得简单多了!

使用如下代码,IE和FF均支持!

var elemstr = $(“#” + name).parent().html();

希望本文能对你有所帮助!

 

wrong above

 

 

jQuery: outerHTML

The outerHTML property (IE only) could sometimes be very handy, especially if you’re trying to replace an element entirely. Brandon Aaron has very kindly given us aouterHTML plugin that does half the job as it doesn’t support replacements. The following code snippet fills in the blanks:

jQuery.fn.outerHTML = function(s) {
return (s)
this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
}

To get the outerHTML value of an element do this…

$('#myTag').outerHTML();

To replace #myTag entirely do this…

$('#myTag').outerHTML("<p>My brand new #myTag.</p>");

Hope this helps someone :)

Update: There’s now a demo page.

posted on
2010-12-08 12:20 
lexus 阅读(
) 评论(
)
编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2010/12/08/1900093.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/148222.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号