Ryan
Ryan

Reputation: 1791

What's the correct OR condition for jQuery?

Is this correct for an OR condition in jQuery?

$('a.clickNews' || '#footer p a:eq(2)').click(function(){
   //statement
});

Thank you.

Upvotes: 2

Views: 5389

Answers (1)

lonesomeday
lonesomeday

Reputation: 237865

No, that will only select 'a.clickNews'. You need to use a comma to separate them:

$('a.clickNews, #footer p a:eq(2)').click(function(){
   //statement
});

See Multiple selector in the API.

Upvotes: 7

Related Questions