Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamic select element with JQuery by id

I need to dynamic select element with JQuery, I get in code id of element. How to do that ? I've tried:

var sel='\'#'+id+'\'';
var elem+$(sel);

but it doesn't work ( id is string id of element).

like image 372
Drkosh Avatar asked Jun 16 '11 09:06

Drkosh


2 Answers

You would use code such as

var ID = 'whatEver';
$('#' + ID).action();

You would then be able to use that to select whatever element you are after.

like image 158
Tom Walters Avatar answered Sep 30 '22 18:09

Tom Walters


You don't need the extra quotes. Just:

var elem = $("#"+id);
like image 26
Luke Dennis Avatar answered Sep 30 '22 17:09

Luke Dennis