Introduction to jQuery
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal, event handling, and animation much simpler with an easy-to-use API that works across a multitude of browsers.
Key Features
- DOM manipulation and traversal
- Event handling
- AJAX support
- Animations and effects
- Cross-browser compatibility
Selectors
Select elements using CSS-style selectors:
$("#id")
$(".class")
$("tag")
Events
Handle user interactions:
$("button").click(function(){
alert("Button clicked!");
});
DOM Manipulation
Change content and structure:
$("#myDiv").text("New text");
$("#myDiv").html("Bold");
CSS Manipulation
Change styles dynamically:
$("#myDiv").css("color", "red");
AJAX
Send asynchronous HTTP requests:
$.ajax({
url: "test.php",
type: "GET",
success: function(result){
$("#div1").html(result);
}
});
Effects
Animate elements:
$("#myDiv").fadeIn();
$("#myDiv").slideUp();
Utilities
Useful utility methods:
$.each([1,2,3], function(index, value){
console.log(index, value);
});
Other Features
- Plugins for extending jQuery
- Chaining methods
- Event delegation