Using Self Calling Anonymous Functions and $(document).ready

This is a common pattern with jQuery extensions to ensure that they are always added to the jQuery object, but can be written using $ to keep the code tidy:

      // your code here

The $ would actually reference the jQuery library inside while still referring to Prototype on the outside! This can help tidy up your code

Source: javascript – Using Self Calling Anonymous Functions and $(document).ready – Stack Overflow

Using jQuery to prevent Internet Explorer from accidentally submitting form on enter key

Works in ajax templated context as well.

jquery – Fade in each element – one after another – Stack Overflow

Let’s say you have an array of span elements:

(quick note: I think you need jQuery 1.4 or higher to use the .delay method)

This would basically wait a set amount of time and fade each element in. This works because you’re multiplying the time to wait by the index of the element. The delays would look something like this when iterating through the array:

Delay 400*0 (no delay, just fadeIn, which is what we want for the very first element)

Delay 400*1

Delay 400*2

Delay 400*3

This makes a nice “one after the other” fadeIn effect. It could also be used with slideDown. Hope this helps!

via jquery – Fade in each element – one after another – Stack Overflow.

jQuery – get a list of values of an attribute from elements – Stack Overflow

$”.object”.attr”level” will just return the attribute of first the first .object element.This will get you an array of all levels:
var list = $”.object”.mapfunction{return $this.attr”level”;}.get;

via selectors – jQuery – get a list of values of an attribute from elements of a class – Stack Overflow.

Short js snippets working with js jquery and bool valuesinput checkboxes

Get value of checkbox (jquery):

– returns bool true or bool false

Set value of checkbox (jquery):

Second parameter can be true or false.

Convert true or false strings to bool (js):

This is when you know the string will be ‘True’ or ‘FALSE’ for instance. Accepts all case variations of ‘TRUE’ and ‘false’.

Use jQuery to hide a DIV when the user clicks outside of it


$(document).mouseup(function (e)
var container = $("YOUR CONTAINER SELECTOR");

if (! // if the target of the click isn't the container...
&& container.has( === 0) // ... nor a descendant of the container

Allan Jardine | Reflections | Visual Event

Events in Javascript are often seen as a bit of an enigma. This is odd given that Javascript is very much an event driven language, but it is typically down to their complex nature and difficulty to debug. To this end I’ve created Visual Event to help track events which are subscribed to DOM nodes.

Allan Jardine | Reflections | Visual Event.

javascript – Window.onload vs document.ready ? – Stack Overflow

The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.

The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds funcionality to the elements in the page doesn’t have to wait for all content to load.

via javascript – Window.onload vs document.ready ? – Stack Overflow.