[英]jquery using find and addClass
我在CSS中使用position:absolute樣式化了一個類(errorPopup),該類從json文件獲取其數據。 我只想在發生錯誤時調用此類。
<div class="parent">
<input class="child" type="text">
</div>
在我的JavaScript文件中,我正在檢查輸入值是否大於data-max。 如果是這樣,我使用我的errorPopup:
$('.child').parents('.parent').find('.errorPopup').addClass('active');
但是,這似乎不起作用。 父母的職位是:相對。
您應該在HTML中有errorPopup類。 如果您正在使用這樣的jquery,
$('.child').parents('.parent').find('.errorPopup').addClass('active');
那么HTML應該像
<div class="parent">
<div class="errorPopup">Please fill out it</div>
<input class="child" type="text">
</div>
注意:默認情況下,CSS中的.errorPopupup應該顯示為:none,.errorPopup.active應該顯示為:block。
謝謝 !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.