cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

    <title>Two-Way Data Binding with jQuery and Object.observe</title>
    <h2 class="_color-red">Update</h2>
    <p>It seems that Object.observe is being replaced this experiment should probably be ignored.</p>
    <hr />
      First Name: <input type="text" data-bind="firstName" />
      Last Name: <input type="text" data-bind="lastName" />
      Age: <input type="number" data-bind="age">
      <select data-bind="color">
        <option value="Red">Red</option>
        <option value="Green">Green</option>
        <option value="Blue">Blue</option>
        <option value="Yellow">Yellow</option>
      Name = 
      <span data-bind="firstName"></span>
      <span data-bind="lastName"></span>
      Age = 
      <span data-bind="age"></span>
      Color = <span data-bind="color"></span>

    Two-Way binding with jQuery and Object.observe
    Author: Josh
    *********** Notice *************
    You will need to be using a browser that
    supports Object.observe currently
    the only browser to do so is
    Chrome Canary V 29+
    You need to turn on Experimental JavaScript
    in chrome://flags
    How to use it
    To use this you would create one Object
    this object will house all of the keys
    you're going to want bound to a(n) element(s)
    on the page. In my example I have firstName
    and lastName. Then you would use the
    data-bind attribute on the element setting
    it's value equal to the key in the Object.
    You will need to run jQuery.bindings([bindings object]);
    It'll traverse the DOM and kick everything off for you.

/* The Plugin */

;(function ( $, window, undefined ) {

  var pluginName = 'bindings';

  function Plugin( bindings ) {
    this.bindings = bindings;
    this._name = pluginName;


  Plugin.prototype.init = function () {
    var self = this;

      var $this = $(this)
      , key = $this.attr('data-bind')
      , hasVal = $this.is('select, options, input, textarea')
      , keyup = $this.is('input, textarea');
      // Bind our Element to change the object
      $this.on('keyup.bindings change.bindings', function(){
        self.bindings[key] = hasVal ? $this.val() : $this.html();
      // Bind our Object to change the element
      Object.observe(self.bindings, function(obj){
        self.observer($this, obj, key);

  Plugin.prototype.observer = function (ele, obj, key) {
      var $elem = ele.jquery === undefined ? $(ele) : ele;
      $elem[$elem.is('select, option, input, textarea')?'val':'html']( obj[0].object[key] );

  $[pluginName] = function ( bindings ) {
      if (!$.data(this, 'plugin_' + pluginName)) {
        $.data(this, 'plugin_' + pluginName, new Plugin( bindings ));

}(jQuery, window));

if(Object.hasOwnProperty('observe')) {
  var binds = {
    firstName: 'John',
    lastName: 'Doe',
    age: 22,
    color: 'Blue'
} else {
  alert('Sorry your browser does not support Object.observe! Please Read "Notice" section in the JS panel.');
Loading ..................