views:

121

answers:

4

Like a tag that I can use to store some necessary info? But really isn’t required or used by the HTML? Works like the tag attribute for objects on Visual Basic?

+2  A: 

You could perhaps use the html5 data-* attributes? It'll fail validation on html4, but it is still probably the best option...

Marc Gravell
Although it will fail a strict validation on html4, it will still work because all browsers accept it, and at the end, that's what really matters.
awe
+6  A: 

Up until HTML5 no. With HTML 5 there is provision for this with the data-* attribute.

For example:-

<div id="myStuff" data-mydata="here is my data">

In current technology there is no "official" away to do this. However all browsers allow you to add any arbitary attribute to a HTML element so in HTML4 you can do this:-

<div id="myStuff" data-mydata="here is my data">

Which as you can see is identical but not offically sactioned and if you want strict XHMTL compliance will be considered "broken".

You can access the attribute just as you would any other:-

var mydata = document.getElementById("myStuff").getAttribute("data-mydata");
AnthonyWJones
Downvoter, comment please?
AnthonyWJones
A: 

Have a look at www.htmlref.com or W3C for the used attributes.

Other than those you can just add your own, they will render and they will be accessible via code for instance in C# you can access a controls attribute collection.

Control.Attributes["MyCustomAttribute"] = "Hello World";

Mark Redman
A: 

there’s rel and rev attributes, which work in elements with an href-attribute. they have a semantic meaning, but are often abused as an attribute to store additional information

knittl
So we should abuse that attributes too?
Gumbo