public
Created

jQuery cheatsheet

  • Download Gist
down_prototype_equivalent.js
JavaScript
1 2 3 4 5 6 7 8
(function($) {
$.fn.down = function() {
var el = this[0] && this[0].firstChild;
while (el && el.nodeType != 1)
el = el.nextSibling;
return $(el);
};
})(jQuery);
get_obj_from_to.js
JavaScript
1 2 3 4
// Get object from index to index
 
$(el); // << return an array of object
$(el).slice(from, to);
plugins.js
JavaScript
1 2 3 4
// Collapsable div for web - not sure about mobile
https://github.com/danielstocks/jQuery-Collapse/
// Know when new element is created.
http://docs.jquery.com/Plugins/livequery
select_el_by_index.js
JavaScript
1 2 3
// fucking useful \m/
// $(el)[1] only returns text instead of object
$(el).eq(index).<whatever jquery function>;
siblings.js
JavaScript
1 2 3
/*
We should use this selector more often since we can separate the part or pack of element, so even if we move the js and html structure later. It still works well
*/
use_on_more_often.js
JavaScript
1 2 3 4
// http://api.jquery.com/on/
// this function will auto bind events to the new element in DOM
// so you don't have to use it manually.
// #GREAT# - This is very nice

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.