I have the following XHTML:
<span id='myid' cus:att='myvalue' xmlns:cus='http://mycompany.com/customnamespace'> </span>
Is it possible to access custom attributes with javascript? I have the element that represents the span. Doing myElement.att doesn’t work, and I can’t figure out how to specify the namespace?
There is a special version of the
getAttributemethod specifically designed for accessing namespaced attributes:getAttributeNS. With your example XHTML, the following JavaScript code:…would return ‘
myvalue‘.You can read more about the
getAttributeNSmethod here.Steve