[Solved] jquery selector with a class and variable id


I’d suggest:

$('#' + elementId + '.control-menu');

Would match <div id="elementID" class="control-menu"></div>

An id is unique; select by that first and then check to see if it has a matching class-name.

Incidentally, your original selector was searching for the element with the id that has an ancestor element with the class of .control-menu.

If the element with the id for which you’re searching is a descendant element of another with the class of .control-menu, then:

$('.control-menu #'+elementid);

Would match <div class="control-menu"><div id="elementID"></div></div>

5

solved jquery selector with a class and variable id