Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

refactoring jquery selector expression

Is there a way that I can write the following selector in a less verbose fashion (the parent id is being repeated again and again).

$("#parent_id .class1 , #parent_id .class2,....")

Thanx!

like image 253
serverman Avatar asked Dec 16 '22 04:12

serverman


2 Answers

$("#parent_id").find(".class1, .class2, .class3").....
like image 132
Matt Wolfe Avatar answered Dec 18 '22 19:12

Matt Wolfe


List your classes in the context of the object like so:

$('.class1, .class2, .class3', $('#parent_id'))

Edit: jsFiddle example.

like image 28
j08691 Avatar answered Dec 18 '22 17:12

j08691