niedziela, 7 kwietnia 2013

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 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-*: 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:

Brak komentarzy: