[英]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.