Wednesday, June 04, 2008

HTML and XForms custom attributes

In your HTML, you can add attributes with any name to an HTML element. This can be helpful for JavaScript libraries. However, if you try to access this attribute as you normally might-- document.getElementById('myelement').myattribute-- you'll get a null back. The solution is to use .getAttribute().

Additionally, with xforms:input and Orbeon, to add custom attributes you need to prefix the attribute with the xhtml namespace, like so:

xforms:input id="fun" xhtml:myattribute="more fun"

This attribute will be applied NOT to the generated HTML element, but to the span containing the HTML input element! So then you need to use the .parentNode attribute of the HTML element to access this SPAN.

No comments:

Labels

Blog Archive

Contributors