Skip to content

Instantly share code, notes, and snippets.

@phrz
Created August 21, 2012 17:07
Show Gist options
  • Save phrz/3417391 to your computer and use it in GitHub Desktop.
Save phrz/3417391 to your computer and use it in GitHub Desktop.
Some simple jQuery tricks and polyfills.
$(function(){
$('html').removeClass('no-js').addClass('js');
$('[autofocus]').focus();
if("placeholder" in document.createElement("input")) {
$('html').addClass('placeholder');
} else {
$('html').addClass('no-placeholder');
}
if($('html').hasClass('no-placeholder')) {
$('[data-placeholder]').each(function(){
$(this).parents().first().prepend('<span class="label">'+$(this).attr('data-placeholder')+'</span>');
});
} else if ($('html').hasClass('placeholder')) {
$('[data-placeholder]').each(function(){
$(this).attr('placeholder',$(this).attr('data-placeholder'));
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment