Styling views table - Toogle row class on click I have a view which is shown as table. I would like to add a css class to entire row, once the user has clicked somewhere on the row.

With views i added '.baza-pregled-strank-row' class to each row. Below is my jquery code, which is successfully loaded, but not doing what it should, because once i click on the view-field, the class is not aded to the row. Big thanks.

(function ($) {
$('.view-field').on('click', function(e) {
      $('.baza-pregled-strank-row').toggleClass("highlight");
      e.preventDefault();
    });
}(jQuery));
First of all you need to add custom class to your VIEWS wrapper and also for TABLE ROW.
I have added my-view-wrapper for the VIEWS and row-wrapper for TABLE ROW




Add CLASS to your VIEWS


Add CLASS to your TABLE ROW







(function ($) {
  Drupal.behaviors.viewRowHighlight = {
    attach: function (context, settings) {
      $('.my-view-wrapper .row-wrapper').click(function(e){
        $(this).toggleClass('clicked');
      });
    }
  };
})(jQuery);