![](/img/trans.png)
[英]get element where the innerhtml text matches a value - Hopscotch and javascript
[英]Hide all 'a' elements with text or innerHTML that matches the number '0' or a custom value using javascript or jQuery
我需要隱藏所有帶有text或innerHTML
<a>
元素,這些元素與數字'foo'匹配,或者使用javascript或jQuery隱藏自定義值。
<li><a href="#" class="dir">foo</a></li>
我努力了
jQuery(document).ready(function() {
if (jquery().text().html("foo"){
('li >a').fadeOut()
}
});
$('a:contains(foo)').hide();
完成。
要么:
var customValue = "foo"
$('a').filter(function(){
return this.innerHTML === customValue;
}).fadeOut();
使用后面的選項,您可以更多地定制它,例如:
var customValue = "foo"
$('a').filter(function(){
return this.innerHTML === customValue &&
$(this).closest('div').length;
}).fadeOut();
一種方法,假設您正在搜索的文本正是您使用的字符串, 無恥地偷偷 向 Jonathan Sampson 致敬 :
創建:exactly
選擇器:
$.extend($.expr[":"], {
exactly: function( element, index, details, collection ){
return $(element).text() === details[3];
}
});
像這樣使用:
$('a:exactly("foo")').fadeOut();
參考文獻:
:exactly()
選擇器: http : //sampsonblog.com/279/creating-your-own-custom-jquery-filters :exactly()
: 是否有任何選擇器與文本完美匹配?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.