[英]select elements having href attribute not starting with a string
$('.el[href^="view.php"]').css('background', 'gold');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a class='el' href = 'view.php?id=323'>lorem</a> <a class='el' href = 'view.php?id=525'>lorem</a> <a class='el' href = 'index.php'>lorem</a> <a class='el' href = 'about.php'>lorem</a>
上面的工作正常,但现在我需要具有href
而不是 view.php
开头的元素。
我尝试没有成功:
$('.el[href^!="view.php"]').css('background', 'gold');
您可以在jQuery的not()
使用Attributes From Selector选择器:
$('.el').not('[href^="view.php"]').css('background', 'gold');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a class='el' href = 'view.php?id=323'>lorem</a> <a class='el' href = 'view.php?id=525'>lorem</a> <a class='el' href = 'index.php'>lorem</a> <a class='el' href = 'about.php'>lorem</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.