Skip to content

Instantly share code, notes, and snippets.

@mattlenz
Created February 20, 2012 07:04
Show Gist options
  • Save mattlenz/1868209 to your computer and use it in GitHub Desktop.
Save mattlenz/1868209 to your computer and use it in GitHub Desktop.
jQuery Placeholder Shim
$.fn.placeholder = ->
@data('placeholder', @attr('placeholder')).removeAttr('placeholder').attr('value', @data('placeholder'))
@on 'focus', ->
$(@).attr('value', '') if @value == $(@).data('placeholder')
.on 'blur', ->
$(@).attr('value', $(@).data('placeholder')) if @value.length == 0
jQuery -> $('[placeholder]').placeholder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment