Skip to content

Instantly share code, notes, and snippets.

@mortennajbjerg
Last active October 1, 2015 16:08
Show Gist options
  • Save mortennajbjerg/2020940 to your computer and use it in GitHub Desktop.
Save mortennajbjerg/2020940 to your computer and use it in GitHub Desktop.
jQuery HTML5 Placeholder fallback
(function($) {
'use strict';
/*global jQuery*/
/*global document*/
$(function() {
// Make sure this only applies to browsers
// without placeholder support
if (document.createElement("input").placeholder !== undefined) { return false; }
// Loop through all input fields to find those using the HTML placeholder attribute
$('INPUT').each(function() {
var $this = $(this);
var searchboxplaceholder = $this.attr('placeholder');
if(searchboxplaceholder) {
// Searchbox placeholder
$this.focus(function() {
if($this.val() == searchboxplaceholder) {
$this.val('');
}
});
$this.blur(function() {
if($this.val() === '') {
$this.val(searchboxplaceholder);
}
});
}
});
});
}(jQuery));
@mortennajbjerg
Copy link
Author

Update where Modenizr detection was removed - and some jslint cleanups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment