Coder Social home page Coder Social logo

jquery-domdatasource's Introduction

jQuery.DOMDataSource

Just a simple interface for getting data from the DOM into Javascript.

Usage

To retrieve semantic data stored in the DOM, pass a hash of accepted attributes to $.DOMDataSource:

<div class="car">
  <span class="color">yellow</span>
  <span class="make">dodge</span>
  <span class="model">dart</span>
</div>

jQuery(document).ready(function ($) {

  var attributes = {
    color: '',
    make: '',
    model: ''
  };

  var car = $('.car').DOMDataSource(attributes);
});

Collections of data can also be retrieved from lists:

<ul>
  <li>
    <span class="color">blue</span>
    <span class="make">amc</span>
    <span class="model">hornet</span>
  </li>
  <li>
    <span class="color">orange</span>
    <span class="make">chevrolet</span>
    <span class="model">corvair</span>
  </li>
</ul>

// in script:
var cars = $('ul').DOMDataSource(attributes);

Finally, data may also be sourced from tables. Note that tables will try and convert the column headers into attribute keys.

<table>
  <thead>
    <tr>
      <th>Color</th>
      <th>Make</th>
      <th>Model</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>green</td>
      <td>oldsmobile</td>
      <td>woodie</td>
    </tr>
    <tr>
      <td>silver</td>
      <td>dmc</td>
      <td>delorean</td>
    </tr>
  </tbody>
</table>

// in script:
var cars = $('table').DOMDataSource(attributes);

Author

RJ Zaworski [email protected]

License

The jquery.DOMDataSource plugin is released under the WTFPL License. You can read the license here.

jquery-domdatasource's People

Contributors

rjz avatar

Stargazers

 avatar

Watchers

 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.