2
$("#minus" + data1[i].PhoneNo[j] + "").on("click", function () {
    $("#textbox" + data1[i].PhoneNo[j] + "").find("input").remove();
});

When I am trying to click the button which is aside the text box,I could not able to delete that particular text box.Can anyone help me out to solve the problem.

Thank you in Advance.

Nikunj Chotaliya
  • 802
  • 8
  • 19

1 Answers1

2

It's better if you can share your HTML code snippet, then it is easier to construct js code, anyway here is the illustration made for you :

Html(let say all of these created by loop process)

// put class name on button for references
// 1st group
<input type="text" class="a" value="a"><button class="removeBtn">Remove</button>
<input type="text" class="a" value="b"><button class="removeBtn">Remove</button>
<input type="text" class="a" value="b"><button class="removeBtn">Remove</button>

// 2nd group
// this code wrapped inside parent container
<hr/>
<div class="container">
  <input type="text" class="a" value="a" />
  <button class="removeBtn2">Remove</button>
</div>
<div class="container">
  <input type="text" class="a" value="b" />
  <button class="removeBtn2">Remove</button>
</div>
<div class="container">
  <input type="text" class="a" value="c" />
  <button class="removeBtn2">Remove</button>
</div>

jQuery

// for first group of textbox
$(document).on('click', '.removeBtn', function() {   
   // Must be noted that, textbox must be aside with button
   // that why we asked for HTML snippet 
   $(this).prev().remove().end().remove();
   // or $(this).prev('.a').remove().end().remove();     
});

// for second group of textbox
$(document).on('click', '.removeBtn2', function () {
  // just remove it parents
  $(this).closest('.container').remove(); 
});

DEMO

Norlihazmey Ghazali
  • 9,000
  • 1
  • 23
  • 40
  • Yes .What you have sent now is exactly right.It worked.Thank You – Naga Bhavani Jul 31 '15 at 07:00
  • 1
    @NagaBhavani make sure about this "It's better if you can share your HTML code snippet," – shafiq.rst Jul 31 '15 at 07:01
  • https://jsfiddle.net/mplungjan/9gccfw73/ In the above fiddle,as iam getting the output,but at text boxes when iam appeding a button and click on the button aside the text box that particular text box must be deleted. – Naga Bhavani Jul 31 '15 at 07:10
  • @NagaBhavani : do you mean when close button was clicked, then all the textbox appeared should be disappeared right? if so, then try this https://jsfiddle.net/metallurgical/9gccfw73/7/ – Norlihazmey Ghazali Jul 31 '15 at 07:24
  • @NorlihazmeyGhazali: I mean that as we are viewing all the details as an output.If we want to edit that particular details ,for example,if i want to delete One number from PhoneNo i should have a button beside each textbox.When i click that particular button that number in the text box and textbox must be deleted. – Naga Bhavani Jul 31 '15 at 07:34
  • Acctually i do't get it about `,if i want to delete One number from PhoneNo i should have a button beside each textbox`, then why not create that button. – Norlihazmey Ghazali Jul 31 '15 at 08:01