user9277191
user9277191

Reputation:

Is there an attribute "data-format" in HTML?

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

Answers (2)

HorusKol
HorusKol

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

robinvrd
robinvrd

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

Related Questions