Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created January 10, 2012 19:26
Show Gist options
  • Save seanbehan/1590651 to your computer and use it in GitHub Desktop.
Save seanbehan/1590651 to your computer and use it in GitHub Desktop.
How To Content Editable
<script>
// coffeescript
$ ->
$("#project_fields .project").live "blur", (event)->
// alert($(this).text())
$field = $(this)
$project_id = $(this).data("project-id")
$data = $(this).text()
$attribute = $(this).data("attribute_name")
$.ajax
url: "/projects/#{$project_id}"
data: "#{attribute}=#{$data}"
method: "POST"
success: (resp)->
$field.highlight()
</script>
<div id="project_fields">
<div class="project" contenteditable=true data-attribute_name="project[name_of_field]" data-project-id="<%= @project.id %>">Hello World...</div>
... more divs
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment