Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep placeholder on focus in IE10

Under WebKit and Firefox, the text in a input's placeholder sticks around on focus—it doesn't disappear until input.val actually has something in it.

Is there a good way to force IE10 to do the same thing?

like image 321
Aaron Yodaiken Avatar asked Jan 21 '13 19:01

Aaron Yodaiken


People also ask

How to keep placeholder on focus in IE?

The trick is to call focus() and select() both on the input element. Show activity on this post. Show activity on this post. I Googled around a bit, and found that there are some CSS pseudo-elements and pseudo-classes that can be used to style placeholders.


3 Answers

The :-ms-input-placeholder pseudo-class documentation from the Internet Explorer Developer Center seems to imply this is working as designed.

The placeholder text is displayed with the specified style until the field has focus, meaning that the field can be typed into. When the field has focus, it returns to the normal style of the input field and the placeholder text disappears.

Edit: If I had to mimic this behavior, I would look at placeholder polyfill libraries (that set the default value, float grey text over the input box, etc) which work with older versions of IE. They would have to be modified, because they probably feature detect the placeholder capability and defer to the browser. Also, this would have a "browser detect" code smell.

Update: An "IE placeholder text disappears" question was asked during a Twitter #AskIE question session on June 19, 2014 and @IEDevChat responded "We have an active bug for this behavior. Next version will provide a fix"

like image 191
Kevin Hakanson Avatar answered Oct 16 '22 11:10

Kevin Hakanson


IE developers responded during the AskIE session on twitter IEDevChat that this is a known bug in IE BugList that they will fix in a future version.

Update:- Unfortunately the placeholder behaviour is still the same in IE11, but seems to work in Edge/Spartan versions.

like image 30
Vivek Pratap Singh Avatar answered Oct 16 '22 12:10

Vivek Pratap Singh


There is no good way to make placeholder stay on field focus in IE 10+ but if you are trying to replace labels with placeholders then you should take a look at this.

http://mozmonkey.com/2014/02/css-only-placeholders-field-labels-i-e-float-labels/

It is way to combine placeholders and label to improve user experience.

like image 3
Mike Starov Avatar answered Oct 16 '22 12:10

Mike Starov