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 can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How do I use the jQuery masked input plugin?
- How do I uncheck a checkbox using jQuery?
- How can I convert jQuery code to vanilla JavaScript?
- How can I convert XML data to JSON using jQuery?
- How can I use jQuery to control the visibility of an element?
- How do I use the jQuery UI Datepicker?
- How do I use jQuery to trigger an event?
- How do I use jQuery to toggle an element?
See more codes...