Using jquery remove how can i remove all the span tags except for the first one..
EDIT
var html = var htm = $("#addin").find(".engagement_data:last-child").find(".keys_values").html(); html=' <span style="display:block;" class="k_v"> <innput type="text" class="e_keys" style="width:65px;" placeholder="key"/> <input type="text" class="e_values" style="width:65px;" placeholder="value"/> </span> <span style="display:block;" class="k_v"> <input type="text" class="e_keys" style="width:65px;" placeholder="key"/> <input type="text" class="e_values" style="width:65px;" placeholder="value"/> </span> ';
Explanation: If we want to remove all items from dropdown except the first item then we can use $('#ddlItems option:not(:first)'). remove(); Here we have excluded first item from being deleted. If we want to remove all items from dropdown except the last item then we can use $('#ddlItems option:not(:last)').
Use . remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed. To remove the elements without removing data and events, use .
Try: $('. chartsbar > div'). remove();
jQuery removeClass() Method The removeClass() method removes one or more class names from the selected elements. Note: If no parameter is specified, this method will remove ALL class names from the selected elements.
Try with:
$(html).not(':first').remove();
or to be more specific:
$(html).not('span:first').remove();
To remove it from DOM, instead of html
variable, use your selector:
$('#addin .engagement_data:last-child .keys_values').not('span:first').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