1

I have a variable where I have stored my checkbox id's but while I am trying to check if the checkbox is selected or not, it's not working fine.

   <script>
   function check(){
       var id = "checkbox1.0";
       if($('#' + id).is(':checked')){alert("checked");} 
   }
   </script>
   <body>
    <input type ="checkbox" id = "checkbox1.0">
    <input type ="checkbox" id = "checkbox2.0" onclick="check()">
   </body>
Mr_Green
  • 39,139
  • 43
  • 154
  • 250
alok verma
  • 47
  • 5

1 Answers1

8

You have to escape the . in your id, but you'd better avoid such ids.

   var id = "checkbox1\\.0";

The demo.

xdazz
  • 154,648
  • 35
  • 237
  • 264