Color the clicked box

Hello,

I want to change the background color of the clicked div boxes

function renk(chkB){
var IsChecked = chkB.checked;        
if(IsChecked){
       chkB.parentElement.parentElement.style.backgroundColor='#FFEB90';
        chkB.parentElement.parentElement.style.color=''; 
  }else{
       chkB.parentElement.parentElement.style.backgroundColor='';
       chkB.parentElement.parentElement.style.color='';
  }
}

My div box
<div class="kutu alt2">2&nbsp;<input type="checkbox" name="pdfsil[]" value="2020-02-10-11-35-pfnnuk81fj8nezqshpj8" onclick="javascript:renk(this);">&nbsp;2020-02-10-11-35-pfnnuk81fj8nezqshpj8</div>

Ek%20A%C3%A7%C4%B1klama%202020-05-30%20194012 Ek%20A%C3%A7%C4%B1klama%202020-05-30%20194111

I just want to color the selected div box

I solved the problem
I deleted one of the repeated “parentElement”

function renk(chkB){

var IsChecked = chkB.checked;

if(IsChecked){

       chkB.parentElement.style.backgroundColor='#FFEB90';

        chkB.parentElement.style.color='#000000'; 

  }else{

       chkB.parentElement.style.backgroundColor='';

       chkB.parentElement.style.color='';

  }

}

backgroundColor

Sponsor our Newsletter | Privacy Policy | Terms of Service