javascript - 我想在链接之间隐藏一个字符

标签 javascript jquery css

我使用 remove() 方法隐藏了类别标签“Featured”,所以它现在被隐藏了我也想用 jquery 隐藏这里的逗号,但我不能。我为此使用了 remove() 方法,但它也隐藏了下一个链接。所以请帮助我的人。谢谢。

<P class="cat">
<a href="#" >Featured</a>
, 

<a href="#">Others</a>
</P>

最佳答案

使用 jQuery select and wrap textNode

$('p').contents()
    .filter(function(){return this.nodeType === 3})
    .wrap('<span />');

我终于想到了这个

Live Demo

// select and wrap all commas
$('.cat')
  .contents()
  .filter(function() {
    return this.nodeType === 3 && $.trim(this.nodeValue)==",";
  })
  .wrap("<span class='comma' />");

// hide all links containing "Featured" as innerHTML
$(".cat").find('a:contains("Featured")').hide();

// select all visible elements
var $coll = $(".cat").children(":visible");
$coll.each(function() {
    var $this = $(this);
    if ($this.prop("tagName")=="SPAN") { 
      if ($coll.index(this)===0 || 
          $this.nextAll(":visible").prop("tagName")=="SPAN") {
        $(this).hide();
      }
    }
});

关于javascript - 我想在链接之间隐藏一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20451274/

相关文章:

javascript - 返回上一页时变量未定义

html - 如何使用 CSS 在图像中添加线性渐变?

html - 我的滚动条隐藏在带有溢出滚动条的固定 div 后面

javascript - JavaScript中有 "null coalescing"运算符吗?

javascript - 正则表达式:如何重复模式匹配?

javascript - 多个 v-for 用于多个对象数组 - 使用相同的索引

javascript - 如何在单击按钮时切换动画

javascript -\u003C 是什么意思?

javascript - 在javascript中保持第二个变量值 "one behind"第一个变量值

javascript - bootstrap-datepicker (范围) - AngularJS 指令