jqueryHow can I use jQuery to hide and show elements?
jQuery can be used to hide and show elements on a web page. It has a .hide()
and .show()
method that can be used to achieve this.
Example code
$(document).ready(function() {
$("button").click(function(){
$("#div1").hide();
$("#div2").show();
});
});
The code above will hide an element with the id div1
and show an element with the id div2
when the button is clicked.
The code consists of the following parts:
$(document).ready(function()
: This part of the code ensures that the code runs only after the page has finished loading.$("button").click(function()
: This part of the code defines the action that will be executed when the button is clicked.$("#div1").hide()
: This part of the code hides the element with the iddiv1
.$("#div2").show()
: This part of the code shows the element with the iddiv2
.
For more information, please refer to the following links:
More of Jquery
- How do I use jQuery to zoom in or out on an element?
- How can I use JQuery with Yii2?
- How can I get the y position of an element using jQuery?
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zip files?
- How can I prevent jQuery XSS vulnerabilities?
- How do I use a jQuery zoom plugin?
- How do I prevent XSS attacks when using jQuery?
- How to use jQuery to achieve a specific task?
- How can I use jQuery to select elements with an XPath expression?
See more codes...