jquery显示/隐藏div点击?

我正在尝试使用jquery来显示和隐藏div onclick,虽然我没有收到任何错误,但它也没有显示或隐藏任何内容。

**编辑 – 更新**

$(document).ready(function() { $("#nav-inner a").click(function() { var type = $(this).attr("class"); $("div.v1 > div").not("." + type).stop().hide().end().filter("." + type).stop().show(); return false; }); 

});

这是jquery:

 $(document).ready(function() { if($("#nav-inner")) { $("#nav-inner ul li a").click(function(evt) { var type = $(this).attr("class"); var rowcount = 0; $('div.v1 .vc').each(function(idx,el) { if(type == 'typea') { if($(el).hasClass('typea')) { $(el).show(); } else { $(el).hide(); } } }); }); } }); 

这是标记:

 
Title
Body
Title 2
Body 2

这可以变得更加简单。

 $(function() { $("#nav-inner a").click(function() { var type = $(this).attr("class"); $("div.vc > div").not("." + type).stop().hide() .end().filter("." + type).stop().show(); return false; }); }); 

你的第一个错误是#nav-inner ul ,其中#nav-inner实际上是ul元素。 上面从点击的链接抓取类,然后选择div.v1的子类与该类并切换它(如果隐藏则显示它,如果没有则隐藏它)。

这是一个更简单的例子..

    
Click the hide and show

 jQuery(".user-profile-info").unbind().click(function(){ if(jQuery( ".user-profile-info" ).hasClass("collapsed")){ jQuery('#user-profile-submenu').css('display', 'block'); jQuery( ".user-profile-info" ).removeClass("collapsed"); } else { jQuery( ".user-profile-info" ).addClass("collapsed"); jQuery('#user-profile-submenu').css('display', 'none'); } });