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