I am try to toggle between js style properties
element.style.display and it behaves weird
Found that is easier toggling classes but would like to know the reason it behaves that way
Hi guys if I’m not wrong when I take an ul element using document.getElement in js it is “converted” into a js object so I can acces it through properties with the display attribute being something like {display: block} so if I applied the following code inside a callback used in a myButton.addEventListener(‘click’, callback)
func callback(){ ul.style.display = (ul.style.display === ‘block’) ? ‘none’ : ‘block’; }
It toggles between ‘block and ‘none’
But why when i write it like this:
func callback(){ ul.style.display =y (ul.style.display === ‘none’) ? ‘block’ : ‘none’; }
The display only toggles after the second click
I found that it is easier to just toggle using classList.toggle() between the class with ‘block’ and ‘none’ but I would like to the te reason why the first way behaves that way. It is driving me crazy hahahaha