javascript - jquery jquery-1.9.0 set div to display:none when I trying to use toggle -
i learning jquery reading book (very book way.)
when tutorial 5 exercise, notice jquery set display:none automatically using jquery-1.9.0. when alter lower version (eg 1.8.3 or 1.6.3), seem work well. wondering if experienced same issue? have worked out version 1.9.0?
below code. can download (http://sawmac.com/js2e/ chapter 5/complete_faq.html)
<html> <head> <meta charset="utf-8"> <title>a 1 page faq</title> <link href="../_css/site.css" rel="stylesheet"> <style type="text/css"> h2 { background: url(../_images/open.png) no-repeat 0 11px; padding: 10px 0 0 25px; cursor: pointer; } h2.close { background-image: url(../_images/close.png); } .answer { margin-left: 25px; } </style> <script src="jquery-1.9.0.js"></script> <script> $(document).ready(function () { $('.answer').hide(); $('.main h2').toggle( function () { $(this).next('.answer').slidedown(); $(this).addclass('close'); }, function () { $(this).next('.answer').fadeout(); $(this).removeclass('close'); } ); // end toggle }); // end ready </script> </head> <body> <div class="wrapper"> <div class="header"> <p class="logo">javascript <i>&</i> jquery <i class="mm">the<br> missing<br> manual</i></p> </div> <div class="content"> <div class="main"> <h1>a 1 page faq</h1> <h2>i've heard javascript long-lost fountain of youth. true?</h2> <div class="answer"> <p>why, yes is! studies prove learning javascript freshens mind , extends life span several hundred years. (note: scientists disagree these claims.)</p> </div> <h2>can javascript solve of problems?</h2> <div class="answer"> <p>why, yes can! it's versatile programming language ever created , trained provide financial management advice, life-saving cpr, , take care of household pets.</p> </div> <h2>is there nil javascript <em>can’t</em> do?</h2> <div class="answer"> <p>why, no there isn’t! it’s able write own public relations-oriented asked questions pages. that’s 1 smart programming language!</p> </div> </div> <div class="footer"> <p>javascript & jquery: missing manual, <a href="http://sawmac.com/">david mcfarland</a>. published <a href="http://oreilly.com/">o'reilly media, inc</a>.</p> </div> </div> </div> </body> </html>
the .toggle()
function has been deprecated in jquery 1.8 , removed in jquery 1.9.
.toggle(function, function, ... ) removed
this "click element run specified functions" signature of .toggle()
. should not confused "change visibility of element" of .toggle()
not deprecated. the former beingness removed cut down confusion , improve potential modularity in library. jquery migrate plugin can used restore functionality.
although, improve if stop using altogether.
javascript jquery css jquery-ui
No comments:
Post a Comment