javascript - How can I avoid the repetetive code in this jQuery code? ANSWERED -
hello making site , code lets me have several pages in 1 .html file. can iterative-ness of code avoided? can simplified?
answered
what mean iterative-ness
?
if want code dry write somthing this:
<script type="text/javascript"> var x = 300; $(function () { $("#indexlink,#betalinglink,#bestemminglink,#leerlinglink").click(function () { $("#content>div").not("#start").hide(x); $("#"+$(this).attr("id").slice(0,-4)).show(x); $('nav>ul>li').removeclass('active'); $('#indexlink').addclass('active'); }); }); </script>
this take selectors, 1 @ time, , create of them run code of yours, same typed, in 1 selector only
edit
fixed div showing
edit2
added jsfiddle show working: http://jsfiddle.net/nicoskaralis/vurjf/
javascript jquery simplify iteration
No comments:
Post a Comment