Reputation: 7021
How can I make a html tag having different attributes ? For example I want have something like this :
<div id="id1" description="description 1" cost="23" owner="me" date_of_purchase="1-1-2014"> first purchase </div>
thanks
Upvotes: 0
Views: 39
Reputation: 208012
You would use data attributes.
So for example:
<div id="id1" data-description="description 1" data-cost="23"
data-owner="me" data-date_of_purchase="1-1-2014"> first purchase </div>
data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as classList, non-standard attributes, extra properties on DOM, or setUserData.
Upvotes: 4
Reputation: 13816
You can just do it like that. But it will not validate. HTML5 specifies the data-* attribute syntax which you can use for custom attributes which will validate and are perfectly OK to use.
So basically prefix your your custom attributes with
data-
<div id="id1" data-description="description 1" data-cost="23" data-owner="me" data-date-of-purchase="1-1-2014">first purchase </div>
Upvotes: 1