-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,703
  • 5
  • 35
  • 49
Saswat
  • 11,464
  • 16
  • 68
  • 141

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
  • 82,599
  • 19
  • 151
  • 169