gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:00:56 25 4
gpt4 key购买 nike

我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com