jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, and animation much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
jQuery HOME is the official website of jQuery, where you can find all the information you need to get started with jQuery. It provides documentation, tutorials, and examples to help you learn how to use jQuery in your web projects.
To get started with jQuery, you need to include the jQuery library in your HTML document. You can do this by adding the following code to the head section of your HTML document:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
This code will include the latest version of jQuery in your document. Once you have included the jQuery library, you can start using jQuery in your web projects.
The syntax of jQuery is designed to make it easy to select HTML elements and perform actions on them. The basic syntax of jQuery is as follows:
$(selector).action()
The $ sign is used to define/access jQuery. The selector is used to select HTML elements, and the action is used to perform an action on the selected elements.
Here are some examples of how to use jQuery:
To select all paragraphs on a page, you can use the following code:
$("p")
To select all elements with a class of "example", you can use the following code:
$(".example")
To select the element with an ID of "example", you can use the following code:
$("#example")
To change the text of an element, you can use the following code:
$("p").text("New text.")
To change the HTML of an element, you can use the following code:
$("p").html("New HTML.")
To change the value of an input element, you can use the following code:
$("input").val("New value.")
To add a click event to an element, you can use the following code:
$("button").click(function(){
alert("Button clicked.");
});
This code will display an alert message when the button is clicked.
jQuery is a powerful JavaScript library that makes it easy to manipulate HTML elements, handle events, and create animations. With its easy-to-use API and cross-browser compatibility, jQuery has become one of the most popular JavaScript libraries in use today.