开发者

How to use a variable in place of ID in jquery

开发者 https://www.devze.com 2023-01-13 09:55 出处:网络
I have a div in which id is generated with index like gal1,gal2,gal3,gal4.... var clickid=\"gal\" + index;

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

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

I want to place the clickid variable inside the jquery selector. How to achieve it开发者_高级运维. This questions looks silly, but im a beginner eager to learn


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


Like this:

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

Since it is an id, you need to prepend # to it so that jQuery is able to find it out. This is similar to CSS :)

For more info, have a look at:

  • jQuery ID Selector
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号