尝试通过jQuery click()单击外部链接来改变一个div的css

时间:2021-12-21 19:45:40

I've tested out the CSS manually to where if I apply

如果我申请,我已经手动测试了CSS

display: none;

then it does what I want, so if I could use jQuery to make this happen by clicking a link on the page, then I'd be set.

然后它做我想要的,所以如果我可以使用jQuery通过单击页面上的链接来实现这一点,那么我将被设置。

I've never altered CSS via jQuery before, so I'm just going to try and explain what I'm trying to do here.

我之前从未通过jQuery改变过CSS,所以我只想尝试解释一下我在这里要做的事情。

I have

我有

<a id="one" href="#">click</a>

and then

接着

<h3 id="two"><a href="#">link</a></h3>

I want to be able to click the first link and then set

我希望能够单击第一个链接然后设置

display: none;

on that h3 labeled 'two.'

在那个h3标记为“两个”。

I appreciate the help guys. This is my first question here, and I usually like to just research the stuff on my own, but I think I'm just missing something fairly similar here and figured I should just ask someone.

我很感激帮助人员。这是我在这里的第一个问题,我通常喜欢自己研究这些东西,但我想我在这里错过了一些相似的东西,并认为我应该问一个人。

3 个解决方案

#1


1  

$('#one').toggle(function() {

    $('#two').hide();

}, function() {

    $('#two').show();

});

#2


2  

Use jQuery's toggle() in it's simplest form. Click to show, click again to hide.

使用jQuery的toggle()是最简单的形式。单击以显示,再次单击以隐藏。

$('#one').click(function(){
    $('#two').toggle()
})

Check working example at http://jsfiddle.net/RjKe8/

#3


0  

$("#one").click(function() {
    $("#two").hide(); // not quite display:none
})

#1


1  

$('#one').toggle(function() {

    $('#two').hide();

}, function() {

    $('#two').show();

});

#2


2  

Use jQuery's toggle() in it's simplest form. Click to show, click again to hide.

使用jQuery的toggle()是最简单的形式。单击以显示,再次单击以隐藏。

$('#one').click(function(){
    $('#two').toggle()
})

Check working example at http://jsfiddle.net/RjKe8/

#3


0  

$("#one").click(function() {
    $("#two").hide(); // not quite display:none
})