Solved

Add Class to Div when clicking a link

Posted on 2016-07-22
1
49 Views
Last Modified: 2016-07-22
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
Comment
Question by:Andrew Spackman
1 Comment
 
LVL 1

Accepted Solution

by:
Andrew Spackman earned 0 total points
ID: 41724726
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question