Skip to content

Instantly share code, notes, and snippets.

@0xqd
Created September 6, 2012 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xqd/3653081 to your computer and use it in GitHub Desktop.
Save 0xqd/3653081 to your computer and use it in GitHub Desktop.
jQuery cheatsheet
(function($) {
$.fn.down = function() {
var el = this[0] && this[0].firstChild;
while (el && el.nodeType != 1)
el = el.nextSibling;
return $(el);
};
})(jQuery);
// Get object from index to index
$(el); // << return an array of object
$(el).slice(from, to);
// 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
// fucking useful \m/
// $(el)[1] only returns text instead of object
$(el).eq(index).<whatever jquery function>;
/*
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
*/
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment