javascript - How to change vertical <tr> into horizontal <tr> -


this code produced 2 things. first 1 highlight table record when checkbox clicked. second 1 remeber result page refreshed.

   <!doctype html>     <html>     <head>     <meta charset="utf-8">     <title>untitled document</title>     </head>      <body>     <style>     .highlight-red {         background-color: red;     }         .highlight-green {         background-color: green;     }     .highlight-yellow {         background-color: yellow;     }         </style>     <div class="col-lg-10">         <table id="table" border="1" >             <tr class="highlight">             <td><input type="checkbox" name="cb1" id="cb1" value="y" onchange="changesoma(this, 'red')" /></td>             <td>click me</td>             </tr>             <tr>             <td><input type="checkbox" name="cb2" id="cb2" value="y" onchange="changesoma(this, 'green')" /></td>             <td>click me</td>             </tr>             <tr>             <td><input type="checkbox" name="cb3" id="cb3" value="y" onchange="changesoma(this, 'yellow')" /></td>             <td>click me</td>             </tr>         </table>     </div>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>     <script>          function changesoma(data, color){                 if(data.checked && color == 'red'){                     $(data).parent().parent().addclass("highlight-red");                 }                 else{                     $(data).parent().parent().removeclass("highlight-red");                 }                 if(data.checked && color == 'green'){                     $(data).parent().parent().addclass("highlight-green");                 }                 else{                     $(data).parent().parent().removeclass("highlight-green");                 }                 if(data.checked && color == 'yellow'){                     $(data).parent().parent().addclass("highlight-yellow");                 }                 else{                     $(data).parent().parent().removeclass("highlight-yellow");                 }         }     </script>     <script>          var cond = json.parse(localstorage.getitem("check"));         for(var in cond) {             if(cond[i]) {              $("#"+i).attr("checked",true);              $("#"+i).parent().parent().addclass("highlight-"+cond[i]);             }         }         function changesoma(data, color){                 var state;                 if(localstorage.getitem("check") == null) {                     state = {cb1:0,cb2:0,cb3:0};                 } else{                     state = json.parse(localstorage.getitem("check"));                 }                  if(data.checked) {                     $(data).parent().parent().addclass("highlight-"+color);                     state[data.id]= color;                 } else {                     $(data).parent().parent().removeclass("highlight-"+color);                     state[data.id]= 0;                 }                 localstorage.setitem("check",json.stringify(state));         }     </script>     </body>     </html> 

enter image description here

but need 3 checkboxes horizontal. when remove tr tags, 1 colors highlight 3 check boxes, other 2 colors doesn't work.it shown below. how can change this? ca explain me bug? enter image description here

just add tr tag. no need deleting it.

style="display: inline-block;" 

should

<tr style="display: inline-block;">     <td><input type="checkbox" name="cb1" id="cb1" value="y" onchange="changesoma(this, 'red')" /></td>     <td>click me</td> </tr> 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -