Hello all im trying jquery and im trying to make a simple tab menu, but i just cant get it to hide my content, you can see what i have made here
开发者_StackOverflow中文版http://jsfiddle.net/YyJ7V/
hope you can tell me what im doing wrong
This is how I'd do it:
$(function() {
var tabContainers = $('div.tabs > div');
tabContainers.hide();
$('.tabsNavigation a').click(
function(){
var which = $(this).parent().index();
$(tabContainers).eq(which).show().siblings().filter('div').hide();
return false;
});
})
JS Fiddle demo.
Notes:
- As implied in my comment to your question: you were using MooTools, rather than jQuery in your demo. This won't work. Or it might, but probably rarely, due to syntax/use-differences
filter()
was misspelled, and so couldn't work.- I I couldn't see, in your demo, any click-handling to effect an action, so I added that in.
http://jsfiddle.net/loktar/YyJ7V/3/
$(function() {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter('#tab1').show();
})
Filter was mispelled, also changed to # instead of :, and it seems to work. Also like David Thomas posted above I had to change it to jquery in js fiddle, it was set to mootools by default.
精彩评论