javascript - How to style specific divs based on checkboxs -
javascript - How to style specific divs based on checkboxs -
okay want alter style of specific divs based on checkboxes beingness clicked..
i have several checkboxs this...
<input type="checkbox" class="the-checkbox" onchange="test()" value="1"> <input type="checkbox" class="the-checkbox" onchange="test()" value="2"> <input type="checkbox" class="the-checkbox" onchange="test()" value="3"> each of these correspond div...
<div class="panel-heading" id="panel-1"> <div class="panel-heading" id="panel-2"> <div class="panel-heading" id="panel-3"> value="1" id="panel-1, id="panel-2"with id="panel-2" etc
these elements dynamic , pulled database.
when checkbox clicked illustration 1 value="1" want alter colour of div "id panel-1".
i need work when multiple checkboxes checked styling "delete entry" functionality.
i having problem doing in javascript here have far...
function test(){ var checkboxes = document.getelementsbyclassname('the-checkbox'); (var i=0 ; < checkboxes.length; i++) { if (checkboxes[i].checked) { var cn = document.getelementsbyclassname('panel-heading')[i].id cn.style.backgroundcolor = "red"; // know line wrong } } }
you on right track
the value of checkbox link between checkbox , div. value 1 corresponds div panel-1 etc. utilize value corresponding div:
correspondingdiv = div id ("panel-" + value of selected checkbox) if (checkboxes[i].checked) { //get value of checkbox var val = checkboxes[i].value; //since value link between checkbox , div, //use corresponding div var correspondingdiv = document.getelementbyid("panel-" + val); //and apply background color correspondingdiv.style.backgroundcolor = "red"; } javascript html css checkbox
Comments
Post a Comment