[英]jquery continuously check if element has specific attribute and do something
我希望在a
具有特定的href
时隐藏div,并在没有该特定的href
时显示它
我试过这个:
if($('a[href="#intro"]').not(".active"))
{ $('.navbar-brand').hide();}
else {$('.navbar-brand').show();}
但是这没有按预期工作,当特定的href
具有一类active
时,它隐藏了div。
我究竟做错了什么 ?
尝试这个
var show = $('a[href="#intro"]').hasClass('active');
$('.navbar-brand').toggle(show);
我觉得你用得不好:看不到https://api.jquery.com/not-selector/
if($('a[href="#intro"]:not(".active")')
{ $('.navbar-brand').hide();}
else {$('.navbar-brand').show();}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.