javascript - I have multiple <td> with the checkbox and its values.I want to change colour of <td> -


below html code contains multiple checkboxes respective values in <td>. got values of clicked checkboxes through php array format $res[]. want make checkbox disappear of got values , make <td> background color red value of checkbox visible. got values of checkboxes in php $res[0][seat]=>4; , $res[1][seat]=>1 4 , 1 values. how using jquery?

<table>     <tr>         <td>             <input name="chk" class='chk' type="checkbox" value="1"/>             <label>1</label>         </td>     </tr>     <tr>         <td >             <input name="chk" class='chk' type="checkbox" value="2"/>             <label>2</label>         </td>     </tr>     <tr>         <td >             <input name="chk" class='chk' type="checkbox" value="3"/>             <label>3</label>         </td>     </tr>     <tr>         <td >             <input name="chk" class='chk' type="checkbox" value="4"/>             <label>4</label>         </td>     </tr> </table> 

updated try this:

var arr=[4,1];// array list received php   for(i=0;i< arr.length;i++){  $('table tbody tr td input[type=checkbox]').each(function(){  	 if($(this).val()==arr[i]){  		  $(this).hide();  		    $(this).closest('td').css('background-color','red');  	 }else if($(this).is(':visible')){  		 $(this).closest('td').css('background-color','pink');  	 }  	});	  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table><tr><td>  <input name="chk" class='chk' type="checkbox" value="1"/>  <label>1</label>  </td></tr>  <tr><td >  <input name="chk" class='chk' type="checkbox" value="2"/>  <label>2</label>  </td></tr>  <tr><td >  <input name="chk" class='chk' type="checkbox" value="3"/>  <label>3</label>   </td></tr>  <tr><td >  <input name="chk" class='chk' type="checkbox" value="4"/>  <label>4</label>   </td></tr></table>


Comments

Popular posts from this blog

javascript - Wordpress slider, not displayed 100% width -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -