显示当前单击的div隐藏先前单击的div [英] show current clicked div hide previous clicked div
问题描述
下面的代码正在工作,但是有一个我不明白的问题. 当我单击第一个导航链接时,它显示了div,这就是我想要的, 但是当我单击另一个导航链接时,它确实显示了预期的下一个div 但我需要隐藏以前的div. 任何帮助表示赞赏.
The code below is working, but with a problem I do not understand. When I click on first navigation link it is showing the div, this is what I want, but when I click on another nav link it does show the next div as expected but I need for the previous div(s) to hide. any help is appreciated.
类似的东西:如果这不是单击的导航链接,则隐藏.我想.
something like: if this is not the nav link that was clicked hide. I would think.
$(document).ready(function(){
$('#navigation a').click(function (selected) {
var getName = $(this).attr("id");
var projectImages = $(this).attr("name");
//console.log(getName);
//console.log(projectImages);
$(function() {
$("#" + projectImages ).show("normal");
});
});
});
推荐答案
您可以尝试向显示的div添加一个类,然后在显示新的div时隐藏该类的元素.像这样:
You could try adding a class to the div you are showing, and then hiding elements with that class when you show the new div(s). Something like this:
$(document).ready(function(){
$('#navigation a').click(function (selected) {
var getName = $(this).attr("id");
var projectImages = $(this).attr("name");
$(function() {
$(".current").hide().removeClass("current");
$("#" + projectImages ).show("normal").addClass("current");
});
});
});
这篇关于显示当前单击的div隐藏先前单击的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!