Run a JavaScript for selected pages (using body class)

Submitted by editor on Thu, 06/02/2016 - 10:07
Question

How to execute JS codes on selected Pages, using drupal body class ? 

Example : Execute JS only in the front page.
This Script run whin the body tag contains class='front'

(function ($) {
    $(document).ready(function () {
        if ($('body').hasClass('front')) {
            alert('Hello');
        }
    });
})(jQuery);

 

Add new comment