Julien Fadel Julien Fadel - 5 months ago 21
Javascript Question

Group selectors javascript with concatenation

Can you group those into one line, I know how to do this without concatenation but with, not working.

$('#vda'+event.target.id).remove();
$('#a'+event.target.id).remove();
$('#'+event.target.id).remove();
$('#da'+event.target.id).remove();

Answer

here is your one liner.

$(
    '#vda' + event.target.id +
    ', #a' + event.target.id + 
    ', #' + event.target.id +
    ', #da' + event.target.id
).remove();

it seems more, but I divided to better readability.

https://api.jquery.com/multiple-selector/ here is the documentation for multiple selector of jQuery

Comments