gaurav
gaurav

Reputation: 1

delete text box dynamically

Can i delete a text box dynamically?

Upvotes: 0

Views: 528

Answers (2)

Andrew Whitaker
Andrew Whitaker

Reputation: 126042

(Edited after seeing comment in OP):

To get StackOverflow-like functionality, you could do something like this:

HTML:

<div class="comment">
This is a test this is a test this is a test.
</div>

JavaScript:

$(".comment").hover(function() {
    $(this).append("<span class='close'>X</span>");
}, function() {
    $(this).find("span.close").remove();
}).delegate(".close", "click", function() {
    $(this).closest("div.comment").remove();
});

Here's a working example: http://jsfiddle.net/andrewwhitaker/xQTSb/

It all looks a little hectic, but here's what's going on:

  • Uses hover, which takes a function to execute on mouseenter and again on mouseleave
  • Inside those functions, the span that removes the comment is added or removed, respectively.
  • delegate is used to bind a click event to the span (necessary because the span does not exist until the user hovers over the comment div).

Upvotes: 1

gergi
gergi

Reputation: 489

$('#your_text_box_id').remove()

Upvotes: 0

Related Questions