要完全除去的話:
$('.subscription-price').each(function(){
var text = $(this).find('.amount')[0].nextSibling;
text.nodeValue = text.nodeValue.replace('29-day free trial','');
});
JS Fiddle demo。
要跟隨第一span
刪除一切:
$('.subscription-price').each(function(){
var text = $(this).find('.amount')[0].nextSibling;
text.parentNode.removeChild(text);
});
JS Fiddle demo。
隱藏它,你需要在另一個元素來包裝,以便CSS針對那些話:
$('.subscription-price').html(function(i,h){
return h.replace('29-day free trial', function(a){
return '<span class="hideMe">' + a + '</span>';
});
});
再加上CSS:
span.hideMe {
display: none;
}
JS Fiddle demo。
或者再次隱藏一切繼span
:
$('.subscription-price').each(function(i,h){
var text = $(this).find('span')[0].nextSibling;
$(text).wrap('<span class="hideMe"></span>');
});
JS Fiddle demo。
要再次隱藏部分1929 -days ......「,允許各種數字被用來代替29
:
$('.subscription-price').html(function(i,h){
return h.replace(/(\d{1,2}-.+)/, function(a){
console.log(a);
return '<span class="hideMe">' + a + '</span>';
});
});
JS Fiddle demo。
顯然,隱藏一切的.amount
元素jQuery的片斷之前的最後一個代碼塊,仍能正常工作下,因爲它不是基於數字隱藏,但其在DOM位置。
什麼是29是什麼值?像19,25,10 –
他們會永遠是數字,他們會一直是兩位數嗎?它是*僅僅是'29日......'的一部分,還是全部是'span'後面的文字? –
永遠是否定的,它將是1-31 –