Ok so i have this structure
<div class="field_with_errors">
<input id="count" name="count" size="2" type="text" />
<label class="message" for="count_for">Required</label>
</div>
How do i remove the outer field_with_errors
and the inner message and just leave the input tag
if I do
$("#count").closest(".field_with_errors").remove()
it removes the entire div
I can remove the inner .message
first but not sure how to remove the outer
$("#count").closest(".field_with_errors").find('.message').remove()
Any ideas
The unwrap() method is an inbuilt method in jQuery which is used to remove the parent element from the selected element. Syntax: $(selector).unwrap()
The empty() method removes all child nodes and content from the selected elements.
To clear the contents of a div element, set the element's textContent property to an empty string, e.g. div. textContent = '' . Setting textContent on the element removes all of its children and replaces them with a single text node of the provided value.
hide() sets the matched elements' CSS display property to none . remove() removes the matched elements from the DOM completely. detach() is like remove() , but keeps the stored data and events associated with the matched elements.
use replacewith()
method,
$(".field_with_errors").replaceWith($("#count"));
here is the fiddle example
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