Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector using element id stored in a var?

Tags:

jquery

I've stored the id of an element as a string, I want to get it using a jquery selector, like:

var theid = $('#test').attr('id');

... later ...

$(theid).remove();

what's the right syntax for running the selector using the string variable which contains the id of the element I want to remove?

Thanks

like image 947
user246114 Avatar asked Dec 09 '22 15:12

user246114


1 Answers

$('#'+theid).remove()

like image 174
Pekka Avatar answered Jan 04 '23 14:01

Pekka