Question

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 -->
Was it helpful?

Solution

Use addClass

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

WORKING DEMO

OTHER TIPS

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

Use this...

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

Hope this will help you...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top