-1

I have some DIVs with IDs like 'abc_chosen', 'danger_chosen', etc.

I would like to delete all DIVs when their IDs contain the string '_chosen'.

How can I do that?

evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
Saswat
  • 12,320
  • 16
  • 77
  • 156

1 Answers1

5

Try this:

$('div[id$="_chosen"]').remove();

$ here will check if _chosen is at the end of id.

Thanks to @evolutionxbox: If you want to check if id contain _chosen anywhere(not at the end)

$('[id*="_chosen"]').remove();

Docs: https://api.jquery.com/attribute-ends-with-selector/

Tushar
  • 85,780
  • 21
  • 159
  • 179