Add class to element on click of another element in jQuery

JavaScript
// jQuery

What it does

Click on #buttonID to add the class newClass to another element .targetElementClass.

This script includes a transition of 250ms.

The Code

$(document).ready(function() {
  $('#buttonID').click(function() {      
    $('.targetElementClass').addClass('newClass',250); // Fade in the effect over 250ms
  })
});

How To Use It

Paste this snippet into a JavaScript file that is loaded by your page, or you can put it between <script> </script> tags in the footer.

jQuery is required.

Menu