DMS-KH
DMS-KH

Reputation: 2787

How to remove a label before input in jquery

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();

enter image description here

Upvotes: 0

Views: 1832

Answers (4)

Amit Visodiya
Amit Visodiya

Reputation: 813

Try This:

$("#amount").prev("label").remove();

or

$("#amount").parent().find("label").remove(); // if not direct previous element

Upvotes: 1

Jai
Jai

Reputation: 74738

You don't need parent():

$("#amount").prev("label").remove();

Upvotes: 1

Adil
Adil

Reputation: 148110

You do not need to call parent(), to get the sibling through prev()

$("#amount").prev("label").remove();

Upvotes: 1

Arun P Johny
Arun P Johny

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

Related Questions