, otherwise $(document).ready() may not fire.
Examples
$(document).ready(function(){
// Your code here...
});
hover(Function, Function)
Description
This is a custom method which provides an 'in' to a frequent task. Whenever the mouse cursor is moved over a matched element, the first function is fired.
Whenever the mouse moves off of the element, the second function fires. On top of this, checks are in place to see if the mouse is still within the element itself (for example, an image inside of a div), and if it is, it will continue to 'hover', and not move out (a common error in Javascript code)
Examples
$("p").hover(function(){
this.$old = this.innerHTML;
$(this).html("Welcome!");
},function(){
$(this).html(this.$old);
});
toggle(Function, Function)
Description
Whenever a matched element is clicked, the first function is fired, when clicked again, the second is fired. All subsequent clicks continue to rotate through the two functions.
Examples
$("p").toggle(function(){
$(this).addClass("selected");
},function(){
$(this).removeClass("selected");
});
Dynamic event(Function)
Description
Shortcuts for using the bind and unbind functions are provided, where you would normally type:
$("p").bind("click",Function);
you can now type:
$("p").click(Function);
This is included for all of the following events
- abort
- blur
- change
- click
- contextmenu
- dblclick
- error
- focus
- keydown
- keypress
- keyup
- load
- mousedown
- mouseenter (Internet Explorer only)
- mouseleave (Internet Explorer only)
- mousemove
- mouseout
- mouseover
- mouseup
- reset
- resize
- scroll
- select
- submit
- unload
Dynamic unEvent(Function)
Description
This is a shortcut, similar to the previous one, but for detaching a Function from a matched element.
Examples
$("p").unclick(Function);
Also, you can leave the function empty and completely remove all of a particular event type. For example, the code below removes all click events from the element.
$("p").unclick();
Dynamic oneEvent(Function)
Description
This is another shortcut, following the same rules as 'onclick, etc.', but will only fire once. This is very useful for buttons, links, etc.
Examples
$("p").oneclick(function(){
alert("Only once!");
});
