2016-03-02 76 views
2

我已經得到了這個,但它似乎沒有做任何事情,但我無法弄清楚爲什麼......語法似乎很好。jQuery:包含在.not()不起作用

$('#entries li').not(function() { 
    return $('span.date:contains("March 2016")', this); 
}).hide(); 

在其他功能使用:

$('#entries li').not(function() { 
    return $('.date', this).text() === formattedDate; 
}).hide(); 

這一個工作正常。

任何幫助將不勝感激。

+0

只需使用有效的解決方案,然後'._。' – Phiter

+0

什麼是你的HTML是什麼樣子? – j08691

+0

那麼你有一個符合這個要求的元素:'span.date:contains("March 2016「)'在你的HTML? – stackErr

回答

3

$('#entries li')這一塊是非常相似的

$('#entries li').not(function() { 
    return $('span.date:contains("March 2016")', this); 
}).hide(); 

因爲你回電話回所有的時間內truthy值。您必須在此上下文中使用.is()函數來完成您的任務。

$('#entries li').not(function() { 
    return $('span.date', this).is(':contains("March 2016")'); 
}).hide(); 

或者乾脆,

$('#entries li span.date:contains("March 2016")').hide(); 
+0

謝謝。是()工作。 不確定你的最後一個例子,但我試圖隱藏所有的東西,但包含日期的條目。但其他人完美地工作。 – Funktion

+0

@Funktion是的。你現在可以使用第二個變體。我在那裏犯了一個錯字。你想隱藏包含數據「2016年3月」的span.date。對? –

+0

是的...和is()完美地工作。排序。謝謝。 – Funktion