Download
User Rating: 0/5 ( 0 votes)
Placeholder Enhanced enhance the use of HTML5 placeholder attribute providing cross-browser support & styling
Features
-
Cross-browser & Cross-styling
-
Support for all input types, password, textarea, text, email, search, url, etc...
-
Robust: it heavely behave as the HTML5 placeholder defined in the specs
-
Normalize placeholder behaviour in modern browsers (optional). This means the placeholder will hide on input focus.
-
Fix jQuery.val() function to work as expected to set/get the value of inputs with placeholder
-
Lightweight: 970 bytes minified & gzipped
Source: github.com
1. INCLUDE CSS AND JS FILES
<link href="css/placeholder-enhanced.css" rel="stylesheet" />
<script src="jquery.js"></script>
<script src="jquery.placeholder-enhanced.js"></script>
2. HTML
<form method="post" id="form" novalidate>
<p><input type="text" name="text" id="text" placeholder="Insert text here" /></p>
<p><input type="email" name="email" id="email" placeholder="Insert email here" /></p>
<p><input type="url" name="url" id="url" placeholder="Insert url here" /></p>
<p><input type="search" name="search" id="search" placeholder="Search" /></p>
<p><textarea cols="50" rows="3" name="textarea" id="textarea" placeholder="Write your comments here"></textarea></p>
<p><input type="password" name="password" id="password" placeholder="Type password here" /></p>
<p>Setting size attribute on password also works fine for unsupported browsers</p>
<p><input type="password" name="passwordSize" id="passwordSize" size="55" placeholder="Type password here" /></p>
<div class="separator"></div>
<p id="submit"><input type="submit" class="btn" value="Send" /></p>
</form>
3. JAVASCRIPT
$('input[placeholder], textarea[placeholder]').placeholderEnhanced();
4. EXAMPLES
Initialize the plugin after loading an HTML page via AJAX, call the plugin after the content is loaded.
$(function () {
$.get('file.html', function (html) {
$('#container')
// append the html
.append(html)
// find any inputs or textareas with placeholder and initialize the plugin
.find('input[placeholder], textarea[placeholder]').placeholderEnhanced();
});
})
If you want to destroy the plugin call:
$('input[placeholder], textarea[placeholder]').placeholderEnhanced('destroy');
It will automatically clean all what the plugin first created as if it was never initialized, only for the selected elements.