如何使用jquery去除noscript标签包装? [英] How to remove noscript tag wrapper with jquery?

查看:130
本文介绍了如何使用jquery去除noscript标签包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除围绕图像的noscript标签:

I want to remove noscript tag that is wrapping round an image:

<a href="some_image.jpg">
 <noscript>
  <img src="some_image.jpg">
 </noscript>
</a>

我试过 unwrap(),但它在noscript中不工作,接下来我尝试了 html()方法:

I tried unwrap(), but it doesn't work inside noscript, next I tried the html() method:

$('a').html(function(index, oldhtml){
   return oldhtml.replace(/\<noscript\\?>/g, '');
});

虽然标签已被移除,但它会生成一个字符串而不是DOM:

Though the tag is removed, it produces a string instead of DOM:

<a href="some_image.jpg">
 "
  <img src="some_image.jpg">
 "
</a>

如何删除noscript标签包装器,同时保持img元素不变?

How to remove the noscript tag wrapper while keeping the img element untouched?

推荐答案

尝试类似 - 它实际上是一个非常粗暴的黑客

jQuery(function($){
    $('a:has(noscript)').html(function(){
        return $(this).find('noscript').text()
    })
})

演示:小提琴

这篇关于如何使用jquery去除noscript标签包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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