0

Can i delete a text box dynamically?

2
  • 1
    It would be helpful to explain what you're trying to do and what you've tried so far. It would also be helpful if you didn't completely replace one question with a different question after someone has already answered. Commented Feb 4, 2011 at 18:01
  • 1
    @Bill the Lizard:I want to delete the text box automatically.If u take stackoverflow if i move a cursor on a comment ,i get a cross icon.How do i do it? Commented Feb 4, 2011 at 18:15

2 Answers 2

1

(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).
Sign up to request clarification or add additional context in comments.

4 Comments

When i move my cursor to edge of text box,i need to have a small cross icon,if i click it should delete
@gaurav: I noticed your comment on the original post and updated my answer.
This is working in jsfiddle but not working in localost,should i need to add js1.5 and use on load.Thnx for that gr8 explanation.
@gaurav: Yes, you need to include jQuery 1.5 in the head element of your document, something like this: <script type="text/javascript" src="jquery.js"></script>
0
$('#your_text_box_id').remove()

1 Comment

When i move my cursor to edge of text box,i need to have a small cross icon,if i click it should delete.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.