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
  • 40,727
  • 45
  • 159
  • 271
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
  • 158,678
  • 38
  • 247
  • 274