Reputation: 560
I create a textarea and javascript code that removes the text in the textarea on press enter my problem is that when press enter it break a line, but I want to prevent the line break. this is my code for removing text from textarea on press enter:
if(e.keyCode == 13 && !e.shiftKey){
function clear() {
$("#mytxt :input").each( function() {
$(this) .val('');
});
}
}
<textarea id="mytxt"></textarea>
so how can I prevent the line break while using my function?
Thanks
Upvotes: 4
Views: 6569
Reputation: 798
if(e.keyCode == 13 && !e.shiftKey)
{
//write your code here
return false;
}
<textarea id="mytxt"></textarea>
Upvotes: 0
Reputation: 392
Add e.preventDefault();
to the end of your function.
https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault
Upvotes: 4