单击一个div可隐藏不同的div(Click one div to hide a different div)

在jQuery中有很多关于隐藏/显示函数的教程,但是找不到任何有关我的问题的教程。 我不是编程的新手,jquery对我来说是第一次。

当用户点击“链接1”等时我想要它...它隐藏了下面的“隐藏我”字样。 目前它部分有效,但它只隐藏了实际的链接...而不是“隐藏我”这个词。 我知道这与选择器有关...但不知道将选择器放在哪里。

谢谢。

简单的小提琴

$(document).ready(function(){ //user clicks on link $('a').click(function(){ //hides the word below link but doesn't work $(this).hide(); }); });

我试过了

$(this).hide("panel");

$("panel", this).hide();

谢谢

There's a lot of tutorials about hide/show functions in jQuery but can't find any regarding my issue. I'm not new to programming, jquery is a first for me.

I would like it when a user clicks on "link 1" etc...it hides the word "hide me" below. Currently it partially works, but it only hides the actual link...not the "hide me" word. I know it's to do with a selector...but not sure where to put the selector in.

Thanks.

Simple js fiddle

$(document).ready(function(){ //user clicks on link $('a').click(function(){ //hides the word below link but doesn't work $(this).hide(); }); });

I've tried

$(this).hide("panel");

and

$("panel", this).hide();

Thanks

最满意答案

更改:

$(this).hide();

至:

$(this).parent().next('.box').hide();

$(this)隐藏了你点击的内容

Change:

$(this).hide();

to:

$(this).parent().next('.box').hide();

$(this) is hiding what you're clicking

单击一个div可隐藏不同的div(Click one div to hide a different div)

在jQuery中有很多关于隐藏/显示函数的教程,但是找不到任何有关我的问题的教程。 我不是编程的新手,jquery对我来说是第一次。

当用户点击“链接1”等时我想要它...它隐藏了下面的“隐藏我”字样。 目前它部分有效,但它只隐藏了实际的链接...而不是“隐藏我”这个词。 我知道这与选择器有关...但不知道将选择器放在哪里。

谢谢。

简单的小提琴

$(document).ready(function(){ //user clicks on link $('a').click(function(){ //hides the word below link but doesn't work $(this).hide(); }); });

我试过了

$(this).hide("panel");

$("panel", this).hide();

谢谢

There's a lot of tutorials about hide/show functions in jQuery but can't find any regarding my issue. I'm not new to programming, jquery is a first for me.

I would like it when a user clicks on "link 1" etc...it hides the word "hide me" below. Currently it partially works, but it only hides the actual link...not the "hide me" word. I know it's to do with a selector...but not sure where to put the selector in.

Thanks.

Simple js fiddle

$(document).ready(function(){ //user clicks on link $('a').click(function(){ //hides the word below link but doesn't work $(this).hide(); }); });

I've tried

$(this).hide("panel");

and

$("panel", this).hide();

Thanks

最满意答案

更改:

$(this).hide();

至:

$(this).parent().next('.box').hide();

$(this)隐藏了你点击的内容

Change:

$(this).hide();

to:

$(this).parent().next('.box').hide();

$(this) is hiding what you're clicking