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.

3
  • 3
    can you paste html code also Commented Jul 31, 2015 at 6:38
  • 1
    stackoverflow.com/questions/750486/… Commented Jul 31, 2015 at 6:38
  • No need to create click handler for each button, you can fallow some common way to register the click handler and delete textbox. Please share your html code Commented Jul 31, 2015 at 6:55

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

6 Comments

Yes .What you have sent now is exactly right.It worked.Thank You
@NagaBhavani make sure about this "It's better if you can share your HTML code snippet,"
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.
@NagaBhavani : do you mean when close button was clicked, then all the textbox appeared should be disappeared right? if so, then try this jsfiddle.net/metallurgical/9gccfw73/7
@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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.