Search code examples
javascriptjquerychaining

chain multiple jquery commands


I've tried chaining and nesting, but possibly in the wrong style is there a more efficient way to execute these two lines?

$('#pub1, #pub1Tab').addClass('active');
$('#pub1').parent().addClass('active');

Solution

  • Try to use jquery parent selector

    $('#pub1, #pub1:parent, #pub1Tab').addClass('active');