Jquery Div 点击隐藏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1092498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery Div Hide on click
提问by karim79
I using coda slider in my page. View it here:
我在我的页面中使用 coda 滑块。在这里查看:
http://www.ndoherty.com/demos/coda-slider/1.1.1/
http://www.ndoherty.com/demos/coda-slider/1.1.1/
Each tab causes the pane to shift the content inside it when it is clicked. I want something ELSEto happen on click. When a tab is clicked, I want an image to appear in the topleft section of the page in a div called "#topleft". For the sake of simplicity, lets just focus on this one div, but I will have other divs activated on click as well.
每个选项卡都会导致窗格在单击时移动其中的内容。我想要的东西ELSE发生的点击。单击选项卡时,我希望图像出现在页面的左上角部分中名为“#topleft”的 div 中。为简单起见,让我们只关注这个 div,但我也会在单击时激活其他 div。
I was thinking of setting the #topleft div to display:none in the CSS, and adding a simple jquery function that sets the #topleft visibility to true when a certain div is clicked. So lets use this for an example: I have a div #nav with 5 divs inside it (each containing their own nav link). When div #nav taba is clicked, I want div #topleft to appear, and when another navlink (say #nav tabb) is clicked I want it to disappear. Can anybody help me out with this fairly simple jquery code? THANKS SOOO MUCH!
我正在考虑在 CSS 中将 #topleft div 设置为 display:none,并添加一个简单的 jquery 函数,该函数在单击某个 div 时将 #topleft 可见性设置为 true。因此,让我们以它为例:我有一个 div #nav,里面有 5 个 div(每个包含自己的导航链接)。当点击 div #nav taba 时,我希望 div #topleft 出现,当另一个导航链接(比如 #nav tabb)被点击时,我希望它消失。任何人都可以帮我解决这个相当简单的 jquery 代码吗?非常感谢!
回答by karim79
Something to the effect of:
有以下作用:
$('#someTabLink').click(function() {
$('#someImage').show();
});
$('#someOtherTabLink').click(function() {
$('#someImage').hide();
});
or using toggle():
或使用toggle():
$('#someTabLink').click(function() {
$('#someImage').toggle();
});
Use the displaycss property as opposed to visibility, if you want something to be initially hidden when your page loads, as the jQuery show, hide and toggle methods work by manipulating the display css property.
如果您希望在页面加载时最初隐藏某些内容,请使用displaycss 属性而不是可见性,因为 jQuery show、hide 和 toggle 方法通过操作 display css 属性来工作。
回答by Ryan
Could you use something like this in jQuery:
你能在 jQuery 中使用这样的东西吗:
$("element").addClass("ClassName")
$("element").removeClass("ClassName")
To remove the class that hides it and add the class which reveales it?
删除隐藏它的类并添加显示它的类?
回答by Ryan
To add to karim79's suggestion, you can make multiple tab links hide the #topleft div like this:
要添加到 karim79 的建议中,您可以使多个选项卡链接隐藏 #topleft div,如下所示:
$('#tabb, #tabc, #tabd').click( function() {
$('#topleft').hide();
});