Hi, Is it possible to use "user defined attribues" in html/xhtml tags? Best regards.
I don't think you can really define/use "custom attributes" -- and, even if you could : how browsers would know what to do with those ?
You probably can inject whatever you want in the "XHTML" document ; but it will not be XHTML valid anymore, I'd say
In HTML as it stands? No.
In XHTML? Kinda. You have to put them in their own namespace and then not serve the document as text/html (which rather excludes Internet Explorer)
In HTML 5? The current draft supports author defined attributes providing they are prefixed with data-
and used only internally.
Use Javascript and define the attribute after load. This way you still have valid HTML.
If you'd like to keep data for an attribute take a look into javascript libraries such as jQuery. Which adds a data() method:
$("div").data("test", { first: 16, last: "pizza!" });
$("span:first").text($("div").data("test").first);
$("span:last").text($("div").data("test").last);
I don't know if it is in specifications, but Yes, you can do that in both HTML and XHTML and all browsers will perfectly understand that. For example:
<html>
<head>
<script>
window.onload=function() {
alert(document.getElementById("data").getAttribute("somenamespace:somevariable"));
};
</script>
</head>
<body>
<div id="data" somenamespace:somevariable="hello world" />
</body>
</html>
This code perfectly works in ALL browsers including IE5.5