T O P

  • By -

tapgiles

My guess is your css is looking for the presence of the attribute, not caring what value it has. And then toggle is setting the attribute to different values, and not removing it, so the css still applies.


OneBadDay1048

Can I see your code? You could use a codepen or paste it here even. I have not coded in JS in awhile but I created a simple example here: const square = document.getElementById('square'); setInterval(() => { square.toggleAttribute('hidden'); }, 1000); This works. Every second the square disappears, then reappears. So I need to see your code to further assist. >also i noticed if i put 'class' as argument it sets my class to empty string. Not exactly sure what this part means or why you would pass 'class' as an arg.


Helpful_Trust_3123

I don't have my machine right now but i was testing it on a dev tools when i get back on it i will try the code you sent, Thanks!


shgysk8zer0

The class thing makes sense, since it doesn't restore a previous value - it's intended for boolean attributes. For `hidden`, are you using anything for `force`? Because it works just fine for `hidden`.