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 ZTree to create a hierarchical tree structure?
- How do I use jQuery to zoom in or out on an element?
- How can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How can I use jQuery to check if an element is visible?
- How do I use a CDN to validate jQuery?
- How do I use a jQuery UI Slider?
- How can I convert jQuery code to vanilla JavaScript?
- How do I use jQuery to detect window resize events?
- How do I use a jQuery queue?
See more codes...