5

The following jQuery statement is working for me. but i don't know either it is a cross-platform independent or not?

$("input[name='confirmed']").attr("checked",false);

Its working on fire fox latest version. Please correct me if i am wrong? Thanks

Abdul Rahman
  • 1,669
  • 4
  • 24
  • 39

4 Answers4

2

As a general rule, JQuery is fully cross-browser compatible. Usually when something doesn't work in one [modern] browser, it won't work in any of them.

I think the most common syntax for dealing with checkboxes is thus:

// set checked state
$("input[name='confirmed']").prop("checked", true);

// remove checked state
$("input[name='confirmed']").prop("checked", false);

// test checked state
$("input[name='confirmed']").is(":checked"); // returns boolean

// pull out only checked inputs
$("input[name='confirmed']").filter(":checked"); // returns collection
amphetamachine
  • 27,620
  • 12
  • 60
  • 72
1

Since you are using the function wrong, it doesn't really matter what browser support for your usage is like.

The second argument of the attr method must be a string, a number or a function (which returns a string or a number).

If you want to remove an attribute, use removeAttr

If you want to twiddle the checked status of an input, then use prop not attr (attr sets the default value for the checked state, not the current value).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

use an on click event

if($("input[name='confirmed']").attr("checked")){
   $("input[name='confirmed']").removeAttr("checked");
} else {
   $("input[name='confirmed']").attr("checked","checked");
}
Cfreak
  • 19,191
  • 6
  • 49
  • 60
budamivardi
  • 722
  • 5
  • 10
0

I have changed my jQuery method attr() to prop() with this way:

$("input[name='confirmed']").prop("checked",false);

and its working fine. Please see the following link for reference:

http://api.jquery.com/attr

Special thanks to Mr. MelanciaUK by giving his precious hint:

Thank you all for your valuable suggestions.

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
Abdul Rahman
  • 1,669
  • 4
  • 24
  • 39