"jQuery is a fast, small, and feature-rich JavaScript library."
1.Google CDN
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
2.jQuery Syntax
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
3. jQuery selector
3.1 Element selector
$("p")
$("button")
3.2 ID selector
$("#id")
3.3 class selector
$(".class")
4. DOM Events
Mouse Events | Keyboard Events | Form Events | Document/Window Events |
---|---|---|---|
click | keypress | submit | load |
dblclick | keydown | change | resize |
mouseenter | keyup | focus | scroll |
mouseleave | blur | unload |
5. on() Method
The on() method attaches one or more event handlers for the selected elements.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").on({
mouseenter: function(){
$(this).css("background-color", "lightgray");
},
mouseleave: function(){
$(this).css("background-color", "lightblue");
},
click: function(){
$(this).css("background-color", "yellow");
}
});
});
</script>
6. jQuery Effect Methods
Method | Description |
---|---|
animate() | Runs a custom animation on the selected elements |
clearQueue() | Removes all remaining queued functions from the selected elements |
delay() | Sets a delay for all queued functions on the selected elements |
dequeue() | Removes the next function from the queue, and then executes the function |
fadeIn() | Fades in the selected elements |
fadeOut() | Fades out the selected elements |
fadeTo() | Fades in/out the selected elements to a given opacity |
fadeToggle() | Toggles between the fadeIn() and fadeOut() methods |
finish() | Stops, removes and completes all queued animations for the selected elements |
hide() | Hides the selected elements |
queue() | Shows the queued functions on the selected elements |
show() | Shows the selected elements |
slideDown() | Slides-down (shows) the selected elements |
slideToggle() | Toggles between the slideUp() and slideDown() methods |
slideUp() | Slides-up (hides) the selected elements |
stop() | Stops the currently running animation for the selected elements |
toggle() | Toggles between the hide() and show() methods |