Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Call checkbox's click event seems erroneous?
  2. $('#my_checkbox').click();
  3.        
  4. (function($) {
  5.   $.fn.flip = function() {
  6.     this.prop("checked", !this.prop("checked"));
  7.     this.triggerHandler("click");
  8.     this.triggerHandler("change");
  9.   };
  10. })(jQuery);
  11.        
  12. $('my_checkbox').flip();
  13.        
  14. (function($) {
  15.   $.fn.flip = function() {
  16.     this.each(function() {
  17.         this.checked = !this.checked;
  18.     });
  19.     this.triggerHandler("click");
  20.     this.triggerHandler("change");
  21.   };
  22. })(jQuery);
  23.        
  24. $("my_checkbox").click(function() {
  25.     var $this = $(this);
  26.     setTimeout(function() {
  27.         // Actually do something with $this
  28.     }, 0);
  29. });