如何使用 JQuery 在 HTML 代码中进行搜索?我想在HTML代码中找到一个字符串,然后隐藏div。这不起作用:
<div class="example">
test
<img src="example.jpg"></div>
$(document).ready(function(){
$(".example:contains('example.jpg')").hide();
});
但是当我告诉它搜索“test”而不是“example.jpg”时,它确实有效吗?
最佳答案
合并:has和 attribute-equals选择器。
$('.example:has([src="example.jpg"])').hide();
这会更有效,因为 :has
是 jQuery 实现的自定义选择器:
$('.example').filter(':has([src="example.jpg"])').hide();
关于jquery - 在 HTML 代码中搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16326012/