2014-02-06 36 views
0

如何删除Jquery中具有不同类和容器的两个元素之间的文本('/')?我需要删除a.main-home和a.home之间的斜线。 .reght_pagenation内的链接数量各不相同。可能吗 ?非常感谢你。如何删除Jquery中两个元素之间的文本?

HTML:

<div class="reght_pagenation"> 
    <a title="Úvod" href="http://www.odsavacky.cz/en">Úvod</a> 
/
    <a title="Produkty" href="http://www.odsavacky.cz/en/produkty">Produkty</a> 
    <a class="main-home" href="http://www.odsavacky.cz" title="Go to Cheiron a.s..">Cheiron a.s.</a> 
/
    <a class="home" href="http://www.odsavacky.cz/en" title="Go to CHEIRÓN a.s. - English.">CHEIRÓN a.s. - English</a> 
/Suction systems 
    </div> 
+0

是否'home'将总是遵循'主 - 主...'或者是否可以存在其他元素 –

+2

见ht tp://jsfiddle.net/arunpjohny/85eAp/1/ –

+0

是的主 - 家总是在家之前。 – user3276426

回答

4

后,您可以找到文本节点main-home并删除它... filter()添加了强制吨双重检查。

var $mh = $('.reght_pagenation .main-home'); 
$($mh.prop('nextSibling')).filter(function(){ 
    return this.nodeType == 3 
}).remove() 

演示:Fiddle

如果结构始终保证是相同的,然后you can omit the filter()

+0

非常感谢,作品像一个魅力。好的一段代码:) – user3276426

1

使用过滤功能这样fiddle

$(".reght_pagenation").contents().filter(function() { 
    return this.nodeType==Node.TEXT_NODE && $(this).text().trim()=="/"; 
}).detach(); 
+0

他们想要一个特定的斜杠删除,不是所有的人。 –

+0

更新回答:添加检查节点文本 –

0

您可以使用过滤功能如下:

$('.reght_pagenation') 
    .contents() 
    .filter(function() { 
    return this.nodeType == Node.TEXT_NODE; 
    }).remove(); 
0

您可以使用简单的的jQuery类似这样的标记:

<script> 
    var test1 = $('.reght_pagenation .main-home'); 
    $(test1.prop('nextSibling')).remove() 
</script> 
相关问题