qadenza
qadenza

Reputation: 9293

clear content of textarea by pressing a specific key

I need to clear content of textarea each time user press the ENTER key.

$("#write").keyup(function(event) {
  if (event.keyCode == 13) {
    $(this).value = "";
    $(this).html = "";
    $(this).text = "";
  }
});
<textarea id="write"></textarea>

Nothing works.

Upvotes: 1

Views: 33

Answers (2)

Dhara
Dhara

Reputation: 1972

You have done correctly but the missing part only is $(this)[0].value=""; when you use val() then select object if you use value then get into the object and use method that is $(this)[0]

Upvotes: 0

gurvinder372
gurvinder372

Reputation: 68433

try this, use val method to get the value

$("#write").keyup(function(event){
if(event.keyCode == 13){
        $(this).val("");
    }
});

Upvotes: 2

Related Questions