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:
If user changes the value on
Of course, this can be done in several ways such as:
There's nothing in this discovery, because their attributes in HTML you can create previously (nobody forbid), but in HTML5 document with attributes
This syntax is also supported by frameworks such as jQuery javascript:
// add and init data-default-value attribute
$('input').data('default-value', 'defaultVal');
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:
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
data-*
:
data-*
is correct for HTML5 validation.
This syntax is also supported by frameworks such as jQuery javascript:
Komentarze