jquery - Show/Hide specified number of table rows -



jquery - Show/Hide specified number of table rows -

i working on html page multiple number of tables, each containing big number of rows. these table rows taking much space on webpage trying create show/hide link below each table display specified number of rows. found out scripts on stackoverflow couldn't them work reason. help appreciated ...

this illustration of tables:

<table border="0" cellspacing="0" cellpadding="0" width="98%" class="dir_cat"> <tr><th><a href="/posts/10-auto/">auto</a></th></tr> <tr class="auto"><td><a href="/cars/">cars</a></td></tr> <tr class="auto"><td><a href="/accessories/">car accessories</a></td></tr> <tr class="auto"><td><a href="/detailing/">car detailing</a></td></tr> <tr class="auto"><td><a href="/car-audio/">car audio</a></td></tr> <tr class="auto"><td><a href="/motorcycles/">motorcycles</a></td></tr> <tr class="auto"><td><a href="/commercial-vehicles/">other commercial vehicles</a></td></tr> </table> <a href="#">show/hide categories</a> <br> <table border="0" cellspacing="0" cellpadding="0" width="98%" class="dir_cat"> <tr><th><a href="0/posts/10-auto/">antiques</a></th></tr> <tr class="antiques"><td><a href="/arch/">architectural</a></td></tr> <tr class="antiques"><td><a href="/art-deco/">art deco</a></td></tr> <tr class="antiques"><td><a href="/art-nouveau/">art nouveau</a></td></tr> <tr class="antiques"><td><a href="/asian-antiques/">asian antiques</a></td></tr> <tr class="antiques"><td><a href="/books/">books</a></td></tr> <tr class="antiques"><td><a href="/publications/">publications</a></td></tr> </table> <a href="#">show/hide categories</a> <br> <table border="0" cellspacing="0" cellpadding="0" width="98%" class="dir_cat"> <tr><th><a href="/art/">art</a></th></tr> <tr class="art"><td><a href="aboriginal/">aboriginal</a></td></tr> <tr class="art"><td><a href="/art-cards/">art cards</a></td></tr> <tr class="art"><td><a href="/drawings/">drawings</a></td></tr> <tr class="art"><td><a href="/fabric-art/">fabric art</a></td></tr> <tr class="art"><td><a href="/folk-art/">folk art</a></td></tr> <tr class="art"><td><a href="/mixed-media/">mixed-media</a></td></tr> <tr class="art"><td><a href="/publications/">publications</a></td></tr> </table> <a href="#">show/hide categories</a> <br>

js:

$("a").click(function(){ $("table tr:gt(3)").toggle(); });

jsfiddle

the next code improve guarantee appropriate tr elements toggle in sympathy. otherwise, depending on inital state, toggle off while others toggle on - ie antiphase!

html

... <a class="tabletoggler" href="#">show/hide categories</a>

jquery

$("a.tabletoggler").on('click', function (e) { e.preventdefault(); var $tr = $(this).prev("table").find("tr:eq(4)").toggle();//toggle tr:eq(4). $tr.nextall().toggle(!$tr.is(":hidden"));//set next trs same tr:eq(4). }).prev("table").find("tr:eq(4)").show().end().end().trigger('click');//this guarantee each tr:eq(4) on, toggle , fellow trs off.

this may seem ott, penalty safety minor. had similar 1 time prepare before screw-up.

jquery html css

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -