jquery Toggle Events

Source: Internet
Author: User

There are HTML page content as follows:
< Body > <  ID= "hh"> Introduction to jquery </h5><   id = "P1" > jquery is a front-end programming language </P   ></body>

You need to implement the ability to click the title to show and hide paragraphs.

The first is implemented by a click method, the code is as follows, it is necessary to pay attention to the use of IS (": visible")

<!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <Scriptsrc=".. /script/jquery-2.1.4.js "></Script>    <title></title>    <Script>        $(function(){            $("#hh"). Click (function(){               if($( This). Next (). Is (": Visible")){                   $( This). Next (). Hide (); }                Else{                   $( This). Next (). Show ();        }            });    }); </Script></Head><Body><h5ID= "hh">Introduction to jquery</h5><PID= "P1">jquery is a front-end programming language</P></Body></HTML>

The second method is used by toggle, when the toggle code is as follows, the effect is to appear a text first

<!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <Scriptsrc=".. /script/jquery-2.1.4.js "></Script>    <title>Toggle</title>    <Script>    $(function(){        $("#hh"). Toggle (function(){            $( This). Next (). Show (); },function(){            $( This). Next (). Hide (); })    })    </Script></Head><Body><h5ID= "hh">Introduction to jquery</h5><PID= "P1">jquery is a front-end programming language</P></Body></HTML>

To achieve the effect of click Switching, the new jquery code should be:

<!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <Scriptsrc=".. /script/jquery-2.1.4.js "></Script>    <title>Toggle</title>    <Script>        $(function(){            $("#hh"). Click (function(){                $( This). Next (). Toggle ( -); },function(){                $( This). Next (). Toggle ( -); })        })    </Script></Head><Body><h5ID= "hh">Introduction to jquery</h5><PID= "P1">jquery is a front-end programming language</P></Body></HTML>

jquery Toggle Events

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.