简体   繁体   中英

How can I compare three elements in js?

When inner has the same text, it doesn't return true. I tried to make variables with these values, doesn't work

const btns = document.querySelectorAll('.btn')
if (btns[0].innerHTML == btns[1].innerHTML == btns[2].innerHTML ){
    //do smth
}

you need to compare one and then the other like this

if (first === second && second === third) {}

in your case it would be like this

const btns = document.querySelectorAll('.btn')
if (
btns[0].innerHTML == btns[1].innerHTML &&
btns[1].innerHTML == btns[2].innerHTML){
    //do smth
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM