iTux iTux - 14 days ago 5
HTML Question

show hide content from Div, show first by default

I was looking for some code to show / hide divs according to item selected from the menu. I found this code, but only works having all divs hidden from start. Could somebody help to modify it to show first option by default?

Here is the fiddle I found http://jsfiddle.net/dangoodspeed/M3ZhV/

I have tried to toggle the view, but it not working :)

var curPage="";
$("#menu a").click(function() {
if (curPage.length) {
$("#"+curPage).toggle();
}
curPage=$(this).data("page");
$("#"+curPage).toggle();
});


Thanks

Answer

If you want the first option to show by default, add this to the top (where curPage is)

var curPage="";

if(!curPage){
    $('#page1').show()
  curPage = "page1"
}
Comments