Skip to content

Instantly share code, notes, and snippets.

@scott-riley
Last active August 29, 2015 13:57
Show Gist options
  • Save scott-riley/9599668 to your computer and use it in GitHub Desktop.
Save scott-riley/9599668 to your computer and use it in GitHub Desktop.
Changing placeholder via media query
// Nice way, using matchMedia, no IE9 or below support
var media = "screen and (min-width: 720px)",
placeholderShort = "Short holder",
placeholderLong = "My quite long placeholder";
$(window).resize(function(){
if(window.matchMedia(media).matches) {
$('.element').attr('placeholder', placeholderLong);
}
else {
$('.element').attr('placeholder', placeholderShort);
}
});
// Slightly not nice way using width
$(window).resize(function(){
var cutoff = 720,
placeholderShort = "Short holder",
placeholderLong = "My quite long placeholder";
if($(window).width() >= cutoff) {
$('.element').attr('placeholder', placeholderLong);
}
else {
$('.element').attr('placeholder', placeholderShort);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment