jeudi 22 août 2019

Javascript ? operator: how to pass multiple parameters

I have the following code:

span.classList.add(span.textContent === '\ ' ? 'char' : 'spaceChar')

It works fine, bud I would like to add 2 classes in case it's true, something like this:

span.classList.add(span.textContent === '\ ' ? 'char','animated' : 'spaceChar')

I tried to use brackets but with no luck:

span.classList.add(span.textContent === '\ ' ? ('char','animated') : ('spaceChar'))

Is there any way to achieve this? Thanks

Aucun commentaire:

Enregistrer un commentaire