Easy Data Binding Plugin For jQuery - databind.js

File Size: 12.1 KB
Views Total: 771
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Easy Data Binding Plugin For jQuery - databind.js

A lightweight jQuery data bindng plugin that makes it easy to bind data to elements using only HTML data attributes. 

How to use it:

1. To begin with, include the databind.js plugin after jQuery.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/jquery.databind.min.js"></script>

2. Add the [data-bind="[$fieldName]"] attribute to the elements as follows:

<input type="text" data-bind="field-example">
<span class="bindSpan" data-bind="field-example"></span>
<select data-bind="field-example">
  <option value=""></option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>

3. Extract the text from the option tag instead of its value attritbue:

<select data-bind="field-otion">
  <option value=""></option>
  <option value="1">label 1</option>
  <option value="2">label 2</option>
  <option value="3">label 3</option>
<input type="text" data-bind="field-otion" data-bind-option-text>

4. Enable an element to toggle the visibility of your elements.

<input type="radio" name="display-example" value="1" checked>
<input type="radio" name="display-example" value="2">

<span data-display="display-example:1">Display content 1</span>
<span data-display="display-example:2">Display content 2</span>

5. Enable the Display Only mode using the display-only class.

<input type="text" class="display-only" value="display-only input">
<select class="display-only">
  <option value=""></option>
  <option value="1" selected>label 1</option>
  <option value="2">label 2</option>
  <option value="3">label 3</option>
<input type="radio" name="display-only-demo" class="display-only" value="1">
<input type="radio" name="display-only-demo" class="display-only" value="2" checked>
<input type="radio" name="display-only-demo" class="display-only" value="3">
<input type="checkbox" name="display-only-demo" class="display-only" value="1">
<input type="checkbox" name="display-only-demo" class="display-only" value="2" checked>
<input type="checkbox" name="display-only-demo" class="display-only" value="3" checked>

6. Set checkboxes and radio buttons to readonly.

$("[name='radioGropu'], [name='checkGroup']").readonlyCheckable();

7. Evaluate the boolean value of an element. Returns null if it is unparseable.

// true
let fieldIsBoolean = $("#fieldBoolean").boolean();

// null
let fieldIsBoolean = $("#fieldNumber").boolean();

// true
let fieldIsBoolean = $("#fieldBooleanFalse").boolean("false");

// false
let fieldIsBoolean = $("#fieldNumber").boolean("true");

8. Evaluate whether parameter or the value of the target dom is undefined, null or blank.

 // OR

9. Change the text of the element.

$("#selector").modify(value => 'prefix ' + value + ' suffix');
$("#selector").modify('prefix ', ' suffix');

10. Increase & decrease the value of the element.



v1.7.0 (2024-03-11)

  • Add event [data-hide] to do the opposite of [data-display].

v1.6.29 (2024-03-11)

  • Bugfix

v1.6.28 (2024-03-05)

  • Bugfixes

v1.6.27 (2024-02-04)

  • Bugfix

v1.6.26 (2024-02-01)

  • Add $(selector).modify() and $(selector).increase() to quickly modify the value or text of the target element.
  • $(selector).boolean() now permits only one element selected.

v1.6.25 (2024-01-31)

  • Bugfixes

v1.6.24 (2024-01-29)

  • Minor optimization.


  • Add $(selector).isBlank() and $.isBlank() to evaluate whether parameter or the value of the target dom is undefined, null or blank.
  • Prevent elements being re-enabled if they are not disabled by [data-display] event.


  • Add $(selector).boolean() to evaluate the boolean value of an element.


  • Add $(selector).readonlyCheckable() to make checkbox or radio elements readonly if they are unmodifiable.


  • [data-display] now bind event on $(document)


  • [data-display] event cannot be triggered when assigned an empty value for checkbox elements fixed.


  • [data-check-field] event now can be chained-triggered.


  • [data-display] event now disabled all elements when hidden.


  • bugfix


  • [data-display] event can accept multiple target values.


  • Add support for jQuery's no Conflict mode.
  • Add [data-bind] event for textarea elements. 


  • Prevent initialization of "display-only" items in hidden templates which is wrapped by a hidden [id*='emplate'] element.


  • Rollback the modification in 1.6.7 and add a new class to achieve the purpose instead.


  • Remove class "display-only" after ready to prevent re-triggering the appending event while using other plug-ins such as tablesorter.js.


  • Minor optimization.

This awesome jQuery plugin is developed by scintilla0. For more Advanced Usages, please check the demo page or visit the official website.