1

I've got a very basic jquery code for adding a new class to an HTML element:

<script>
$('#sign-in').on('click', function() {$(this).toggleClass('display-none');
});
</script>

It adds the display-none class to the div container with an id of #sign-in when it's clicked. However what I want is to add this class to a div with another id. How is that possible?

What I want finally:

<div id="sign-in"></div> <!-- The div to be clicked -->
<div id="new"></div> <!-- The div I need to add the .display-none class to when the previous div is clicked -->
4

3 回答 3

0
<script>
$('#sign-in').on('click', function() {
    $('#new').addClass('display-none');
});
</script>
于 2013-10-26T08:41:04.657 回答
0

使用addClass

<script>
$('#sign-in').on('click', function() {$(this).toggleClass('display-none');
$("#new").addClass("display-none");
});
</script>

工作演示

于 2013-10-26T08:36:20.087 回答
0

用这个...

<script>
$('#sign-in').on('click', function() {
$("#new").addClass("display-none");
});
</script>

希望对你有帮助...

于 2013-10-26T08:46:11.283 回答