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
classvariable name it's reserved keyword. moreover, avoid usingidvariable name it's generic.
Comments
Post a Comment