Remove the element using jQuery

I have a code to delete the text box wen the '-' button is clicked

<!DOCTYPE html>
<script src=""></script>
    var i=1;
    var id=1,text;
    text = '<li id="input_'+id+'" ><input type="text"/> <button id="btn2">-</button> </li>';
        var number = document.getElementById("num").value;
        for(var $j=i; $j<= number; $j++){

        var parent=$(this).parent().prev().attr("id");
        var parent_im=$(this).parent().attr("id");

<input type="number" id="num" autofocus="true"></input>
<button id="ok">OK</button>
<button id="btn1">+</button>
<div class="divi">


Whichever '-' is clicked, the 1st box is removed. I want to remove that particular box to which the '-' button is placed. Can anyone help me do this. Thank You in advance

Edit: How can i delete the last row(textbox and ' - ' button) on click of a button which is placed next to the ' + ' ie,

<button id="btn1">+</button>
<button id="btndel">-</button>

Answers 1

  • Try this........


Related Articles