好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

jquery outerhtml

jquery outerhtml

让 Firefox 支持 outerHTML (使用jQuery1.3) Posted on 2009-06-16 17:43  吕霖  阅读(627)  评论(7)   编辑   收藏  

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 a outerHTML plugin  that does half the job as it doesn't support replacements. The following code snippet fills in the blanks:

view source print ?

jQuery.fn.outerHTML =  function (s) { return   (s) ?  this .before(s).remove() : jQuery( "&lt;p&gt;" ).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( "&lt;p&gt;My brand new #myTag.&lt;/p&gt;" );

Hope this helps someone 

Update:  There's now a  demo page .

查看更多关于jquery outerhtml的详细内容...

  阅读:44次