r/badcode • • Sep 21 '21

js My friend hiding a card in javascript

Post image
319 Upvotes

20 comments sorted by

View all comments

Show parent comment

16

u/[deleted] Sep 22 '21

I'm saying that they shouldn't set hidden to be false because it's bad style; they should remove the attribute entirely (https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute). Unless you need to support IE, classList is fine (https://developer.mozilla.org/en-US/docs/Web/API/Element/classList).

I mistakenly said that setting hidden to false won't work on every browser. I could have sworn I saw that in action at some point, but I'm not finding any resource that backs up my claim

11

u/keethraxmn Sep 22 '21

There are oddities in hiding stuff in IE (old versions at least) but I think it's display:none that's the issue. Too lazy to look it back up.

3

u/cmd-t Sep 22 '21

4

u/[deleted] Sep 22 '21

I guess I'm wrong about that then. Learn something new every day