Confused with jQuery show/hide for images -
i have 7 images lined on 1 of pages. have show/hide functionality working shows odd images "odd" button , shows images "even" button. way works if click on odd button, shows odd. , vise versa ones.
however, if odd images shown , click on button, want them shown, adds them shown. if nothing shown, clicking on button should show images? same thing odd images.
but if images shown, clicking should show images , hide odd ... clicking odd should show odd , hide even.
i hope makes sense. not sure how work. need conditional statement? don't know check for.
here working code, not how want work.
<script> $(function () { $("#evenbutton").click(function () { $("img").show("slow"); $("img:even").show("slow"); }); }) </script> <script> $(function () { $("#oddbutton").click(function () { $("img").show("slow"); $("img:even").hide("slow"); $("img:odd").show("slow"); }); }) </script>
i'm finding hard understand question want images toggle between hidden , shown when button pressed?
i've updated based on read through of question
$("#evenbutton").click(function () { if($("img:even").is(':visible') && $("img:odd").is(':visible')) { $("img:odd").toggle("slow"); } else { $("img:even").show("slow"); } }); $("#oddbutton").click(function () { if($("img:odd").is(':visible') && $("img:even").is(':visible')) { $("img:even").toggle("slow"); } else { $("img:odd").show("slow"); } });
Comments
Post a Comment