Alain
Alain

Reputation: 36954

What is the best way to create my own html attributes?

I create a lof of attributes on HTML tags to play with jQuery and its $(selector).attr() method. For example, if I have a dynamic form with generated fields, I will have a index="xxx" attribute.

What is the best way to create such customised attributes without violating doctype?

Upvotes: 0

Views: 107

Answers (1)

Pekka
Pekka

Reputation: 449395

HTML 5's data- attributes might be for you. They're likely to be the easiest way.

Also, jQuery's .data() supports them natively.

Here's an article explaining the concept in detail.

An example from that article:

<ul id="vegetable-seeds">
  <li data-spacing="10cm" data-sowing-time="March to June">Carrots</li>
  <li data-spacing="30cm" data-sowing-time="February to March">Celery</li>
  <li data-spacing="3cm" data-sowing-time="March to September">Radishes</li>
</ul>

Upvotes: 5

Related Questions