Fork me on GitHub

DIY

jquery-placeholder

A jQuery plugin that polyfills the HTML5 "placeholder" attribute.

View the Project on GitHub diy/jquery-placeholder

jQuery "placeholder" Attribute Polyfill

A basic jQuery plugin that reads the "placeholder" attribute (HTML5) and renders the placeholder text as an overlay (if not natively supported). Unlike most other plugins, this works by adding a properly-positioned <span> on top of the input element rather than setting its value. This keeps form serialization & validation from breaking.

Usage

$('input,textarea').placeholder();

Options

Option Type Default Description
force bool false If true, artificial placeholder elements will be added even if the browser natively supports them.

CSS Styling

.placeholder { color: #d0d0d0; }
::-webkit-input-placeholder { color: #d0d0d0; }
input:-moz-placeholder, textarea:-moz-placeholder { color: #d0d0d0; }

Demos

Emulated Placeholders

  • Vanilla (no styles):

  • Non-standard padding, border, and margin:

  • Absolute positioning:

Native Placeholders

  • Vanilla (no styles):

  • Non-standard padding, border, and margin:

  • Absolute positioning:

License

Copyright (c) 2010 DIY Co

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.