tags:

views:

35

answers:

2

Hi,

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

+7  A: 

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

Pekka
+1: That's good catch.
Sarfraz
+3  A: 
var theid = $('#test').attr('id');

.. what? How is this any different than:

var theid = 'test';
Matt