jQuery
jQuery is a fast, small, and feature-rich JavaScript library. It simplifies things like HTML document traversal and manipulation, event handling, and animation, allowing developers to write concise and efficient code. Here's a simple example of how you might use jQuery to change the text of a paragraph element when a button is clicked:
Sample program of JQuery
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Example</title>
<!-- Include jQuery library -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<p id="myParagraph">Initial text</p>
<button id="myButton">Click me</button>
<script>
// Wait for the document to be fully loaded
$(document).ready(function(){
// When the button is clicked
$("#myButton").click(function(){
// Change the text of the paragraph
$("#myParagraph").text("New text!");
});
});
</script>
</body>
</html>
In this example:
- We include the jQuery library in the
<head>
section of the HTML document using a<script>
tag that points to the jQuery CDN (Content Delivery Network). - We have a paragraph element with an id of "myParagraph" and a button element with an id of "myButton".
- Within a
<script>
tag, we use jQuery to wait for the document to be fully loaded ($(document).ready()
), then we attach a click event handler to the button using theclick()
function. - When the button is clicked, the text of the paragraph element is changed to "New text!" using the
text()
function.
0 Comments
I really appreciate for your words. Thank you very much for your comment.