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 zip files?
- How do I use jQuery to detect window resize events?
- How do I download a zip file using jQuery?
- How can I get the y position of an element using jQuery?
- How do I use a jQuery x-csrf-token?
- How do I add a zoom feature to my website using jQuery?
- How can I prevent jQuery XSS vulnerabilities?
- How can I use jQuery to yield a result?
- Include latest jQuery library version into HTML
See more codes...