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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -