Code Monkey home page Code Monkey logo

contenteditable's Introduction

contenteditable

contenteditable is a tiny jQuery utility which adds useful behaviour to contenteditable text.

Usage

The element with the contenteditable attribute must be wrapped by an element with a class of contenteditable. To make an h1 editable, for example, use:

<h1 class=contenteditable><span contenteditable>Romeo & Juliet</span></h1>

When a user clicks the editable text the browser inserts the caret as near as possible to the cursor. contenteditable also listens for click events on the containing element (the h1 in the above example). The event handler focuses the editable element and selects its text. To take advantage of this handler, include CSS similar to the following:

.contenteditable {
  display: inline-block;
  background: url(images/edit.png) no-repeat right;
  padding-right: 24px;
}

contenteditable also listens for the enter/return keystroke when text is being edited, in response to which it triggers a "contentedited" event. This custom event provides a hook for application code, which might be along these lines:

$('#play').bind('contentedited', function (event) {
  $.post('/path/to/resource', {title: $(event.target).text()})
})

contenteditable's People

Contributors

davidchambers avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.