Reputation: 2787
I'm stuck now I want to remove a label before input in a form. that label was append from another function and I want to delete it back by using jquery method. but if I used insertAfter to add and used on next() and remove() it work as well but I want to add that label before input and if i used before to remove it will remove input instead of labels.
<div class="form-group">
<label>Default balance : 1000</label>
<input name="amount" class="form-control" id="amount" placeholder="" style="" value="0" type="text">
</div>
JS:
$("#amount").parent().prev("label").remove();
Upvotes: 0
Views: 1832
Reputation: 813
Try This:
$("#amount").prev("label").remove();
or
$("#amount").parent().find("label").remove(); // if not direct previous element
Upvotes: 1
Reputation: 148110
You do not need to call parent()
, to get the sibling through prev()
$("#amount").prev("label").remove();
Upvotes: 1
Reputation: 388316
The label
is the previous sibling of the input element #amount
, so call prev()
on the input
element, not on its parent
$("#amount").prev("label").remove();
Upvotes: 2