• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 84
  • Last Modified:

Add Class to Div when clicking a link

Hi,

I have a script that I have done to try and add a class to a container after the user has clicked on it. However it doesn't seem to work. Is there an error in my script below?

<script type="text/javascript">
jQuery(document).ready(function($) {    
    jQuery('.form-toggle').click(function(){
      
        jQuery('.contact-form-container').addClass('form-popout');    
    },    
    function(){    
        jQuery('.contact-form-container').removeClass('form-popout');    
    });
});  

</script>

Many Thanks,

Andrew
0
Andrew Spackman
Asked:
Andrew Spackman
1 Solution
 
Andrew SpackmanHead of CreativeAuthor Commented:
Its Ok I sorted it by using toggleclass instead

<script type="text/javascript">
jQuery(document).ready(function($) {    
    jQuery('.form-toggle').click(function(){
      
        jQuery('.contact-form-container').toggleClass("form-popout");
});  
});
</script>

Thanks anyway
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now