1

I am using a javascript slider that changes the visibility of the '' after 1s interval. On transition complete, I want to check if visible div's hasClass '.white'.

I have achieved it using jquery but want to do the same using plain javascript, I've tried multiple things but failed. Looking for guidance, thanks.

<div class="wrapper">
<div style="display:none;"><a class="btn black">Text 1</a></div>
<div style="display:block;"><a class="btn white">Text 2</a></div>
<div style="display:none;"><a class="btn white">Text 3</a></div>
</div>

Jquery Code

if($(".wrapper>div:visible .btn").hasClass('white')){
console.log('true');
}
itsMe
  • 623
  • 3
  • 9
  • 23
  • document.getElementsByClassName('white').length it#s one way to do it – CMartins Apr 08 '19 at 12:34
  • 2
    This is not similar to hasClass function because the tricky part here is the ':visible' check. – itsMe Apr 08 '19 at 12:34
  • document.getElementsByClassName('white').length will check if 'white' is visible, I want to check if '.wrapper>div:visible .btn' hasClass 'white'. There can be multiple divs with class 'white'. – itsMe Apr 08 '19 at 12:35
  • maybe this will help https://zellwk.com/blog/css-values-in-js/ – CMartins Apr 08 '19 at 12:37

0 Answers0