0

Um trying to remove an HTML element by JQuery as follows

$('#' + divId + ' .settings_class').remove('.print_settings');

This does not throw an error or remove the html element. but the selector correctly retrieves the element.

$('#' + divId + ' .settings_class .print_settings');

How to remove an element inside a div by its class as follows?

not 0x12
  • 19,360
  • 22
  • 67
  • 133
  • `$('#' + divId + ' .settings_class .print_settings').remove();` will remove. – Jai Jan 05 '15 at 06:34
  • Alternatively, using the selector syntax: `$('#' + divId + ' .settings_class div').remove('.print_settings');` – Abhitalks Jan 05 '15 at 06:42

2 Answers2

2
$('#' + divId + ' .settings_class').find('.print_settings').remove();
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
  • this didnt remove the elelent – not 0x12 Jan 05 '15 at 06:42
  • @Kalanamith: Your syntax is perfectly valid. You have to just specify *what* elements of class `.print_settings`: `$('#' + divId + ' .settings_class div').remove('.print_settings');`, assuming your elements are `div`s. – Abhitalks Jan 05 '15 at 06:44
1

If $('#' + divId + ' .settings_class .print_settings'); retriving correct element then use remove() on it! like

$('#' + divId + ' .settings_class .print_settings').remove();

Bharadwaj
  • 2,535
  • 1
  • 22
  • 35