2

I am trying to uncheck the checked checkboxes when the page loads.I have used below code its working fine in mozilla and chrome, but its not working IE. So please help me some alternatives. Jquery version is 1.4.4.

 $("#filter-form").find("input[type='checkbox']").each( function() {
  $(this).removeAttr('checked'); 
  //$(this).attr("checked",false);//just for testing i tried this, but this one also not working in IE.
  }); 
Suraj
  • 297
  • 3
  • 18

4 Answers4

0

In modern versions of jQuery you should be using prop and not attr to set checked state. You would use .prop( "checked", false );

But an easy fix is to change checkbox state would be to change

$(this).removeAttr('checked'); 

to

this.checked = false;
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • It should work. Is it actually getting into the each? – epascarello May 04 '16 at 12:46
  • In mozilla and firefox its going into the each. but in IE no, its not going into that only. – Suraj May 04 '16 at 12:48
  • So what does `console.log($("#calender-filter-form").length);` and `console.log( $("#calender-filter-form").find("input[type='checkbox']").length)` report? – epascarello May 04 '16 at 12:50
  • sorry for my above comment, I checked again, its going into that each loop in IE also. but checked box is not getting uncheck. – Suraj May 04 '16 at 12:51
  • I am writing this code inside (function($){}).any problem with this. – Suraj May 04 '16 at 12:58
0

another option: use PROP instead of ATTR

$(this).prop("checked", false);
imvain2
  • 15,480
  • 1
  • 16
  • 21
  • prop we can use after 1.6 version of jquery.. but mine is older one, so thats not getting work – Suraj May 04 '16 at 12:54
0

$(document).ready(function(){
$("#calender-filter-form").find("input[type='checkbox']").each( function() {
  $(this).removeAttr('checked'); 
  //$(this).attr("checked",false);//just for testing i tried this, but this one also not working in IE.
  }); 
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="calender-filter-form">
  <input type="checkbox" checked/>

 <input type="checkbox" checked />
  <input type="checkbox" />
  <input type="checkbox" />
</div>

working in IE 10

Akram Khan
  • 114
  • 8
  • I am writing this code inside (function($){}).any problem with this. – Suraj May 04 '16 at 13:06
  • 1
    you use only document.ready will work for more detail http://stackoverflow.com/questions/3528509/document-readyfunction-vs-function – Akram Khan May 04 '16 at 13:23
0

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<div id="calender-filter-form">
  <input type="checkbox" checked/>

 <input type="checkbox" checked />
  <input type="checkbox" />
  <input type="checkbox" />
</div>

your code also working in IE 10.tell me which version of IE you are using.

Akram Khan
  • 114
  • 8