Attributes data-* in HTML5

Using HTML5 Web applications becomes a reality. Even the banks are starting to require users to use browsers that support this standard. An example is Getin Bank, which from May 1 recommends the use of new browsers (Firefox 12 +, Chrome 15 +, IE 9 +, Safari 5 +, Opera 10 +).

Creating web application often have the need to create a javascript component (such as jQuery) in which we want to preserve its state. An example would be a simple text box that appears in the browser, and it is initiated by default: <input name="fieldName" type="text" value="defaultVal" /> If user changes the value on userVal, and we want to add a button restores the default value of this field to defaultVal we have a problem.

Of course, this can be done in several ways such as:
  • variable in javascript, we need to ensure that the name of the variable to be unique
  • create a hidden field and in this field store the default value
However, HTML5 gives us new opportunities in this area. Namely allows you to define custom attributes in HTML elements - they have to start from data-*: <input name="field1" type="text" value="defaultVal1" data-default-value="defaultVal1" /> There's nothing in this discovery, because their attributes in HTML you can create previously (nobody forbid), but in HTML5 document with attributes data-* is correct for HTML5 validation.
This syntax is also supported by frameworks such as jQuery javascript: // add and init data-default-value attribute $('input').data('default-value', 'defaultVal');

Komentarze

Popularne posty z tego bloga

Java ESL program for connecting to the FreeSWITCH

AngularJS example MotoAds more advanced than the tutorial on angularjs.org

Java program for connecting to the FreeSWITCH XML-RPC