JQuery remove textarea placeholder when clearing textarea text
I have a Bootstrap modal with a text area. When you open a modal, the textbox should be cleared of any previous text to keep it fresh every time you open it.
The problem is that the placeholder in the field is also removed the first time the text is cleared.
I am using $('textarea').val('')
to clean up text.
source to share
You need to fire the event blur
for the placeholder to appear again. And it only works during the hide event, so when it reappears, the placeholder is returned.
$('#modal').on('hide', function() {
$(this).find('textarea').val('').blur();
});
jsfiddle works
EDIT . I was wrong, it seems to work without blur, just changing the event from show
to hide
as explained by Martin in his answer where he uses the eventshown
source to share
Among IE versions .. IE 10 only supports placement holder .... So don't try to use this tiger in older IE versions ...
but other browsers like firefox, Chrome, Opera ... support this attribute ...
try the below code, it will help you ...
Updated script: http://jsfiddle.net/dkRS8/6/
$(document).ready(function() {
$('#modal').on('show', function() {
var ele = $(this).find('textarea');
ele.val('');
});
});
source to share