How to use variable instead of id in jquery

I have a div in which id is generated with an index like gal1, gal2, gal3, gal4 ....

var clickid="gal" + index; $('WANT TO PLACE clickid HERE').click(); 

I want to put the clickid variable inside the jquery selector. How to achieve this. These questions look silly, but I'm starting to look forward to learning

+4
source share
2 answers
 $("#" + clickid).click(); 
+7
source

Like this:

 $('#' + clickid).click(); 

Since this is id , you need to add # to it so that jQuery can find it. This is like CSS :)

For more information, browse:

+3
source

All Articles