Several Methods for displaying and hiding a div using JQuery-js

Source: Internet
Author: User
This article briefly introduces several methods for displaying and hiding Divs. This article summarizes several methods for displaying and hiding Divs, including style, CSS, and JQuery, for more information, see Example

The Code is as follows:


$ ("# Top_notice" ).css ("display", "block"); // method 1st
// $ ("# Top_notice"). attr ("style", "display: block;"); // method 2nd
// $ ("# Top_notice"). show (); // method 3rd



1. Change the element to the class to hide p, provided that the hidden attribute is defined for the new class style.

The Code is as follows:


$ ("# SendPhoneNum"). attr ("class", "n_input3 ");


1.2 set the style attribute for the element

The Code is as follows:


$ ("# Top_notice"). attr ("style", "display: block ;");


2. Use jquery's css method to set p hiding

The Code is as follows:


$ ("# SendPhoneNum" ).css ("display", "none ");


3. Use the show () and hide () Methods of jquery to set p hiding.

The Code is as follows:


$ ("# TextDiv"). show (); // display p
$ ("# ImgDiv"). hide (); // hide p

P is often used to show and hide p in programming. The following describes several methods:

The Code is as follows:


Example



1. $ ("# demo"). attr ("style", "display: none;"); // hide p
$ ("# Demo"). attr ("style", "display: block;"); // display p
2. $ ("# demo" ).css ("display", "none"); // hide p
$ ("# Demo" ).css ("display", "block"); // display p
3. $ ("# demo"). hide (); // hide p
$ ("# Demo"). show (); // display p
4. $ ("# demo"). toggle (
Function (){
$ (This). attr ("style", "display: none;"); // hide p
},
Function (){
$ (This). attr ("style", "display: block;"); // display p
}
);

For your reference only!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.