jQuery selector with missing "#" and "." -


i've got dirty working code function. looks wrong, clean it. here's snippet:

var id = 'foo1';           //$(this).closest('.myclass').attr('id'); var class = 'morefoo';     //$(this).attr("class").split(" ").pop()  $('#' + id + ' .' + class).show(); 

someone have idea how write more intelligent? webstorm doesn't '#' + myvar + ' .' not really.

there's not can here. concatenate , build selector first , assign variable like,

var elmid = 'foo1';  var elmclass = 'morefoo';  var elmsel = '#' + elmid + ' .' + elmclass;  $(elmsel).show(); //this way, can use elmsel instead of concatenating every time 

note: cannot use class variable name it's reserved keyword. moreover, avoid using id variable name it's generic.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -