jQuery 删除除 anchor 之外的所有 HTML 标签

标签 jquery html

目前,我有这一行:

this.html(this.html().replace(/\x3C\x2F?[^\x3E]+\x3E/gi, ''));

但是,我想说一些类似“if 子句”的东西,

IF (this.tag = "<a") {
  do nothing
} ELSE {
  remove tag
}

我想没有人有任何想法吗?

[编辑]:我想我可能必须做一个“FOR EACH”循环……我想……[/EDIT]

^.^

最佳答案

jQuery 有“:not”伪选择器。

$(':not(a)', this).remove()

关于jQuery 删除除 anchor 之外的所有 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3083225/

相关文章:

php - 通过php或者jquery根据category生成html

php - jQuery ajax 脚本无法与 PHP 中的 n 个表单一起使用

javascript - 使用 JQuery slidetoggle() 时屏幕不向下滚动

javascript - 使特定字符(或类/ID)成为字符串的中心点

javascript - Accordion 的 `aria-role` 应该是什么?在可访问性检查期间,我的 Accordion 被读取为按钮,这可能会使用户感到困惑

html - 如何在 Rails 中没有模型的情况下使用 date_select 表单助手?

javascript - 触发点击具有多个类的元素

javascript - 在一行中显示搜索表单和导航栏菜单项

javascript - jvectormap - 在预定义为选定的区域上禁用 onclick 事件

html - 如何在 ie 7 中使用 html 和 css 水平和垂直居中 IMG 标签?