I have this table element called semana2 in <tr> tag. How can I hide/show using only javascript (no jQuery)
I try this and won't work: document.getElementById('semana2').style.visibility = false;
false isn't a valid value for the visibility property.
You should use one of these options:
myElement.style.display = "none" (hide, and don't show an empty space) myElement.style.visibility = "hidden" or myElement.style.opacity = 0 (hide, but show an empty space where the element would be).opacity has the nice property that it can be animated with a CSS transition, although you should be aware of limited compatibility with IE < 9.
Incidentally, The valid values for visibility are visible | hidden | collapse - See the MDN documentation.
document.getElementById('semana2').style.display = "none";
Visibility is also ok but you have to use it like:
document.getElementById('semana2').style.visibility = "hidden";
Just a note though, if you use visibility "hidden" the box of your element will still be rendered. I.e.: if you have a div 20x20 and apply visibility = "hidden"; to it, you will end up with a 20x20 empty square. While if you set display = "none"; then it will be like nothing is there at all.
display: none and visibility: hidden are not interchangable - they have different behaviours. @Carlos it's not funny - it's just the CSS spec. Also, visibility has been supported in every major browser for ages - there are no compatibility problems. It even works in IE 4.
style.visibility = hiddeninstead ofstyle.visibility = false;falseis not a valid value forvisibility. Tryhiddeninstead. But you might be looking fordisplay:nonerather than that..."hidden", nothidden, by the way.