For example, I have 2 elements like this:
<div id="id_1">ELement 1</div>
<div id="id_2">ELement 2</div>
<div id="not_id">different id</div>
how can I remove just all elements beginning with "id_",.?
thanks,.
You can use an attribute starts with selector:
$("[id^='id_']").remove();
Edit (see comments)
Your question says "all elements", which is why the selector in my example is not as specific as it potentially could be. If you care about performance (in the real world, making this selector more specific is not going to make a noticable difference), then you should make your selector as specific as possible. If it is only div
elements you care about, apply the "starts-with" selector to div
elements only:
$("div[id^='id_']").remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With