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 add a zoom feature to my website using jQuery?
- How do I prevent XSS attacks when using jQuery?
- How do I use a jQuery UI Slider?
- Remove multiple classes from element
- How do I download a zip file using jQuery?
- How do I use the jQuery toggleClass() method?
- How do I use jQuery to post JSON data?
- How can I use jQuery to zoom an image when the user hovers over it?
See more codes...