Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery attr() function is cross-platform independant isn't

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

like image 633
Abdul Rahman Avatar asked Oct 01 '22 01:10

Abdul Rahman


1 Answers

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
like image 105
amphetamachine Avatar answered Oct 03 '22 01:10

amphetamachine