Skip to content

Instantly share code, notes, and snippets.

@BlakeWilliams
Created August 9, 2011 00:35
Show Gist options
  • Save BlakeWilliams/1133146 to your computer and use it in GitHub Desktop.
Save BlakeWilliams/1133146 to your computer and use it in GitHub Desktop.
Form Default Text in Coffeescript
jQuery ($) ->
jQuery.fn.defaultValue = (text) ->
this.each ->
return if this.value != "" or this.value == text
this.value = text
jQuery(this).toggleClass "inactive"
$(this).focus ->
if this.value == text or this.value == ""
this.value = ""
jQuery(this).toggleClass "inactive"
$(this).blur ->
if this.value == text or this.value == ""
this.value = text
jQuery(this).toggleClass "inactive"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment