atlMapper
atlMapper

Reputation: 764

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');

Upvotes: 1

Views: 123

Answers (2)

Ram
Ram

Reputation: 144739

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

Upvotes: 1

antejan
antejan

Reputation: 2624

Try to use jquery parent selector

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

Upvotes: 1

Related Questions