A selector using the identifier of an element stored in var?

I saved the id of the element as a string, I want to get it using the jquery selector, for example:

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

what is the correct syntax to trigger a selector using a string variable that contains the id of the element i want to remove?

thanks

+4
source share
2 answers

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

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

.. what? How is this different from:

 var theid = 'test'; 
+4
source

Source: https://habr.com/ru/post/1314016/


All Articles