Reputation:
I have found this code in one video, but can't find the data-format
attribute in HTML specification.
<input type="text" class="form-control bfh-phone" data-format="+7(ddd)-ddd-dd-dd" />
Upvotes: 4
Views: 4639
Reputation: 8706
You're right, there is no data-format
attribute in HTML5
However, HTML5 is designed to allow some arbitrary attributes to provide some extensibility. These are the data-*
attributes. These can be accessed by javascript to help enhance the presentation or, likely in this case, provide validation rules, or other behaviour.
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
Prefixing with data-
means the arbitrary attribute can be accessed via the element's dataset list.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
Upvotes: 7
Reputation: 1848
All data-*
attributes are used to interact easily with Javascript with element.dataset.*
.
html
<div id="toto" data-test="abc"></div>
javascript
console.log(document.getElementById("toto").dataset.test);
// will display "abc" in console
Upvotes: 5