[英]Get value of <span> based on other <span> class within div?
[英]Toogle div based on span class value
我有以下塊
<div id="discountText">
<span>some text</span>
<span class="discountType" style="display:none;">
</div>
installerDiscountType
包含折扣類型(首選,已保存等)
在<span class="discountType"
等於“ AAA”的情況下,如何顯示div
並在它等於其他值的情況下隱藏它?
我嘗試了多種方法,但一直得到未定義的值。
這將顯示“ Some Text AAA”,因為該范圍沒有類“ discountType”,所以將顯示“ Some Text”
let types = document.querySelectorAll('.discountType')
types.forEach(node => {
if(node.innerText !== "AAA") {
node.style.display = 'none';
}
})
<div id="discountText">
<span>some text</span>
<span class="discountType">Hello world</span>
<span class="discountType">AAA</span>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.