jquery tab like effect - show hide div on click -


i'm learning jquery, , i'm trying create tab effect "upon click, single div should show @ time", have wrote following, don't feel correct way of doing things tho code works. idea how can improve this? maybe make function?

here working demo

$(document).ready(function(){   $("#tabone").click(function(){         $('#box-one').css("display", "block");         $('#box-two').css("display", "none");         $('#box-three').css("display", "none");   }); });  $(document).ready(function(){   $("#tabtwo").click(function(){         $('#box-one').css("display", "none");         $('#box-two').css("display", "block");         $('#box-three').css("display", "none");   }); });  $(document).ready(function(){   $("#tabthree").click(function(){         $('#box-one').css("display", "none");         $('#box-two').css("display", "none");         $('#box-three').css("display", "block");   }); }); 

thank you

use common class .box based on can hide , show div using selected index()

html

<ul id="ul-menu-list">     <li id="tabone">how works</li>     <li id="tabtwo">features</li>     <li id="tabthree">faq</li> </ul> <di id="box-one" class="box">tab one</di> <di id="box-two" class="box">tab two</di> <di id="box-three" class="box">tab three</di> 

js

$(document).ready(function(){     $("#ul-menu-list li").click(function () {         $('.box').hide().eq($(this).index()).show();  // hide divs , show current div     }); }); 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -