Here is a quick snippet showing how to add a class to an existing class using jquery.  You would use this in a situation where you are unable to modify the actual html in a file or where you may not want to.  A great example would be if you want to add a class to a an element that exists through a WordPress plugin.  Sure, you could go into the actual plugin folder and add the class but the next time that plugin updates you will lose the class.  A better solution is to add the class through your theme using jquery.  Here is the snippet:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script><!-- Include the Jquery-->

<script type="text/javascript">// <![CDATA[
$(document).ready(function(){
    $(".exisitingclass").addClass("newclass");
});
// ]]></script>

Replace the “existingclass” with the class that is already assigned and then replace “newclass” with the class you would like to add. This is also interchangeable with an id.

Leave a Reply

Get in Touch

Please fill out the form below and we will get back to you ASAP

  • This field is for validation purposes and should be left unchanged.