Skip to content

Instantly share code, notes, and snippets.

@scan
Created October 14, 2011 12:46
Show Gist options
  • Save scan/1287007 to your computer and use it in GitHub Desktop.
Save scan/1287007 to your computer and use it in GitHub Desktop.
Source of jQuery Toggle Button
$ ->
$('.toggle, .pressed').each ->
$('<input>', { type: 'hidden', name: $(this).data('name'), value: 'on' }).appendTo($(this))
$('.toggle').click ->
$btn = $(this)
$btn.toggleClass 'pressed'
if $btn.is '.pressed'
$('<input>', { type: 'hidden', name: $btn.data('name'), value: 'on' }).appendTo($btn)
else
$btn.find("input[name=#{$btn.data 'name'}]").detach()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment