我使用 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 />');
我终于想到了这个
// 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/