Why is classList.contains does not see the class?

There is here such code
document.documentElement.onclick = function(e) {
 var target = e.target;

 while ( target != this ) {

 if ( target.classList.contains('select') ) {
 var selectOptions = document.querySelector('.select__options');
console.log(selectOptions.classList);
console.log(selectOptions.classList.contains('show'));
 if ( !selectOptions.classList.contains('show') ) {
selectOptions.classList.add('show')
 document.body.onclick = function() {
selectOptions.classList.remove('show')
}
 } else {
selectOptions.classList.remove('show');
}
}

 target = target.parentElement;
}
}

When I first hit the block with the class "select" block class "select__options" add a class "show". When you press again the block with the class 'select', selectOptions.classList.contains('show') returns false. What's the problem?
Here is the console.log
nCcSHPeqHUg.jpg
March 23rd 20 at 18:55
1 answer
March 23rd 20 at 18:57
Magic, of course, but classList is a wonderful method toggle that can help https://developer.mozilla.org/ru/docs/Web/API/Elem...

In addition, I recommend your question to make the link with the code, for example, https://codepen.io/ or https://www.plnkr.co/
nothing works, it doesn't help. It seems to be such an easy task, but I'm stuck :(
https://codepen.io/anon/pen/YbgVKx - Fatima_Lynch commented on March 23rd 20 at 19:00
@Fatima_Lynch, I'm stupid, I understand :) - Fatima_Lynch commented on March 23rd 20 at 19:03

Find more questions by tags JavaScript