4

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

1
  • Why would you ever do this? you have to have the id to query for the id attribute? why not skip a step and just store '#test' in theid?
    – Zack
    Commented Jun 27, 2010 at 14:39

2 Answers 2

9

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

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

.. what? How is this any different than:

var theid = 'test';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.