Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

uses prop() instead of attr()

jQuery 1.6+
  • Loading branch information...
commit cc285fbf418a2ac5e0589401ea079ee9d6efd317 1 parent 9dbd650
nicolas-t authored

Showing 1 changed file with 20 additions and 19 deletions. Show diff stats Hide diff stats

  1. +20 19 jquery-checkbox-2.0.js
39 jquery-checkbox-2.0.js
@@ -10,6 +10,7 @@
10 10 * @package jquery
11 11 * @subpakage ui.checkbox
12 12 * @author Tomasz Wójcik <labs@tomekwojcik.pl>
  13 + * @contributor Nicolas Turlais
13 14 */
14 15 (function() {
15 16 jQuery.fn.checkbox = function(options) {
@@ -26,13 +27,13 @@
26 27 var self = jQuery(this);
27 28
28 29 var replacement = jQuery(
29   - '<div class="' + settings.className + '-wrapper">' +
30   - '<a class="' + settings.className + '" href="#" name="' + self.attr('id') + '"></a>' +
31   - '</div>'
32   - );
33   - var element = jQuery('a', replacement);
34   -
35   - if (self.attr('checked') === 'checked') {
  30 + '<div class="' + settings.className + '-wrapper">' +
  31 + '<a class="' + settings.className + '" href="#" name="' + self.attr('id') + '"></a>' +
  32 + '</div>'
  33 + );
  34 + var element = jQuery('a', replacement);
  35 +
  36 + if (self.prop('checked')) {
36 37 element.addClass(settings.checkedClass);
37 38 }
38 39
@@ -41,24 +42,24 @@
41 42 event.stopPropagation();
42 43
43 44 var input = jQuery('input#' + jQuery(this).attr('name'), replacement.parent());
44   - if (input.attr('checked') === 'checked') {
45   - input.removeAttr('checked');
46   - } else {
47   - input.attr('checked', 'checked');
48   - }
49   - input.trigger('change');
  45 + if (input.prop('checked')) {
  46 + input.removeAttr('checked');
  47 + } else {
  48 + input.prop('checked', true);
  49 + }
  50 + input.trigger('change');
50 51
51 52 return false;
52 53 });
53 54
54 55 self.on('change', function(event) {
55 56 var input = jQuery(this);
56   - if (input.attr('checked') === 'checked') {
57   - jQuery('a[name=' + input.attr('id') + ']', replacement.parent()).addClass(settings.checkedClass);
58   - } else {
59   - jQuery('a[name=' + input.attr('id') + ']', replacement.parent()).removeClass(settings.checkedClass);
60   - }
61   -
  57 + if (input.prop('checked')) {
  58 + jQuery('a[name=' + input.attr('id') + ']', replacement.parent()).addClass(settings.checkedClass);
  59 + } else {
  60 + jQuery('a[name=' + input.attr('id') + ']', replacement.parent()).removeClass(settings.checkedClass);
  61 + }
  62 +
62 63 return true;
63 64 });
64 65

0 comments on commit cc285fb

Please sign in to comment.
Something went wrong with that request. Please try again.