Skip to content

Instantly share code, notes, and snippets.

@sahinsf
Created June 13, 2012 20:21
Show Gist options
  • Select an option

  • Save sahinsf/2926276 to your computer and use it in GitHub Desktop.

Select an option

Save sahinsf/2926276 to your computer and use it in GitHub Desktop.
jQ30-Complete
//The POINTS
window.jQuery = window.$ = jQuery
using CSS selector or jQuery helper or jQuery method // $('li:first-child') vs. $('li':first) || $('li').first()
this refferring the regular DOM node
$(this) jQuery wrapped // jQuery methods can be used
use direct used JQ methods instead of refferred helper methods
// .hover ==> .on('mouseenter', )
// .click ==> on.('click', function(){}) because earlier is refferring latter
CACHE Dom Querying if used multiple times // var $this = $(this);
use CHAINING for not using same methods multiple times
STACK management // .end() // .andSelf()
use EVENT DELEGATION,, attach event handler to the parent instead of every child element
also updated elements or newly generated elements will not have event handler attached if event is not delegated to a parent or if the parent was not covering new elements
// $('dl').on('mouseenter', 'dt', function(){
// - Avoid unnecessary iteration. Most jQuery methods provide "implicit
// iteration" -- they will operate on all of the elements in a selection.
// Additionally, many methods allow passing a function that will operate
// on each method in the selection.
use html5 // $(this).attr('data-file'); == $(this).data('file'); //unlimited custom attributes
parents =~ children
closest =~ find
append ~ prepend ~ after ~ before (working with existing element)
appenTo ~ prependTo ~ insertAfter ~ insertBefore (IF you are CREATING the element)
//var co = $('span.co').each(function(){
var co = $('article').find('span.co').each(function(){ // => parent.find ==> better performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment