jqueryHow do I use jQuery to create a simple example?
jQuery is a JavaScript library that makes it easy to manipulate the DOM (Document Object Model) of a webpage. To create a simple example using jQuery, you can use the following code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#div1").text("Hello World!");
});
});
</script>
</head>
<body>
<div id="div1"></div>
<button id="btn1">Click Me</button>
</body>
</html>
This code will create a webpage with a button and an empty div. When the button is clicked, the text "Hello World!" will appear in the div.
The code is composed of the following parts:
- The jQuery library is imported from a CDN (Content Delivery Network).
- An anonymous function is declared and called when the document is ready.
- An event listener is attached to the button to listen for a click.
- When the button is clicked, the text "Hello World!" is inserted into the div.
For more information about jQuery, you can refer to the official jQuery Documentation.
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zoom an image when it is clicked?
- How do I use jQuery to zoom in or out on an element?
- How do I use jQuery to set query parameters?
- How do I create a jQuery Yes/No dialog?
- How can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How do I download a zip file using jQuery?
- How do I create a quiz using the jQuery plugin?
- How do I set the height of an element using jQuery?
See more codes...