everybody! I want to do following: When clicked on check box one or more div tags must change their css-style. I have this little javascript:
function changeStyle(o) {
if(o.checked) {
document.getElementById(o.getAttribute("value")).setAttribute('class','on');
}
else {
document.getElementById(o.getAttribute("value")).setAttribute('class','off')
}
}
and the html is:
<input type="checkbox" onclick="changeStyle(this);" value="div1" /> Div1<br />
<input type="checkbox" onclick="changeStyle(this);" value="div2" /> Div2<br />
<input type="checkbox" onclick="changeStyle(this);" value="div3" /> Div3<br />
<input type="checkbox" onclick="changeStyle(this);" value="div4" /> Div4<br />
<input type="checkbox" onclick="changeStyle(this);" value="div5" /> Div5<br />
<div id="div1" class="off">I'm in div 1</div><br />
<div id="div2" class="off">I'm in div 2</div><br />
<div id="div3" class="off">I'm in div 3</div><br />
<div id="div4" class="off">I'm in div 4</div><br />
<div id="div5" class="off">I'm in div 5</div><br />
<div id="div2" class="off">I'm in div 2</div><br />
But in this case when I have more than one div with the same id only the first div changes its style from .on to .off
How can I make so when I click on check box to change the css-style to all div tags with same id as the check box value?
Thank you in advance!