Category Archives: jQuery

jQuery related.

jQuery from ‘live’ to ‘on’

jQuery’s live event handler is deprecated (as of version 1.7) and no longer supported (as of version 1.9). The new event handler is called on. Here’s how to migrate your scripts.

Before:

1
2
3
$(".my_selector").live("click", function(e) {
    // ...
});

Now:

1
2
3
$(document).on("click", ".my_selector", function(e) {
    // ...
});

jQuery Serialize form to JSON

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$.fn.serializeObject = function()
{
   var o = {};
   var a = this.serializeArray();
   $.each(a, function() {
       if (o[this.name]) {
           if (!o[this.name].push) {
               o[this.name] = [o[this.name]];
           }
           o[this.name].push(this.value || '');
       } else {
           o[this.name] = this.value || '';
       }
   });
   return o;
};