I have a bit of an issue with a toggle visibility function which operates on the hidden
attribute of an element. Trouble is, this lacks browser compatibility..
function hide(e) {$(e).hidden=true;}
function show(e) {$(e).hidden=false;}
Googling this issue I came across the method of toggling the style.display property, like so..
function toggle(e) {
document.getElementById(e).style.display = (document.getElementById(e).style.display == "none") ? "block" : "none";
}
..but this seems sub-optimal, because you can't have a generic show/hide function that sets the display property to block
. What if the element in question sometimes is supposed to have a inline
or something?
How does for example jQuery solve this issue?
See Question&Answers more detail:os