I would like to hide Elements by class name. I found a working example that runs outside of a function. However, when I use onClick it doesn't seem to work anymore. Please take a look at the following example: http://jsfiddle.net/SkfDz/9/ Can anyone please help me?
HTML:
<input class="" name="options" id="opt1" type="radio" onClick="hideToday()"/><label for="opt1">Hide today</label>
<input class="" name="options" id="opt1" type="radio" onClick="hideToday()"/><label for="opt1">Hide today</label>
<div class="today">TODAY</div>
<div class="today">TODAY</div>
<div class="today">TODAY</div>
<div class="tomorrow">TOMORROW</div>
Script:
function hideToday() {
var todayElements = document.getElementsByClassName('today'), i;
for (i = 0; i < todayElements.length; i += 1) {
todayElements[i].style.display = 'none';
};
};
var tomorrowElements = document.getElementsByClassName('tomorrow'), i;
for (i = 0; i < tomorrowElements.length; i += 1) {
tomorrowElements[i].style.display = 'none';
}