Jquery to highlight a listview row not working correctly

Hello

I am using jquery to highlight in a different colour just the selected row of a listview, so that only one row is highlighted at any one time

Why does the below code not work

<style>

.active {

background-color: red;

}

</style>

    $(function () {

        $('.ListView2 tr').click(function () {

          $('tr').removeClass('active');

            $(this).addClass('active');

        });

    });


Can you please help, if you remove this line   $('tr').removeClass('active'); it will highlight the selected row but not delete the previously selected row that is what this line of code just above is for, but not working correctly, thanks


1 Reply 1 reply marked as answer

GJ Gary Joseph August 19, 2023 10:10 PM UTC

Hello 

After two days have found the answer, this code works

$(function() {

  $('.ListView2 tr').click( function() {

    $(this).addClass('active').siblings().removeClass('active');

  });

});

Thanks anyway



Marked as answer
Loader.
Up arrow icon