JavaScript Reference/Javascript Methods/createAttribute
"createAttribute()" Example
<html>
<body>
<script language="JavaScript">
function function1() {
var newAttr = document.createAttribute("width");
newAttr.nodeValue = "400px"
document.getElementById("myB").setAttributeNode(newAttr);
}
</script>
<table id="myB" border=3 cellpadding="5" style="border-color:blue">
<tr>
<th>Expand this table</th>
<th>This is another cell</th>
<tr>
</table>
<input type="button" value="Add attribute to the table" onclick="function1();">
</body>
</html>
"createAttribute()" is applied to
+----------------+--------------------------------------------------------------+
| Applied_To |document |
+----------------+--------------------------------------------------------------+
"createAttribute()" Syntax, Parameters and Note
Note:
Creates an attribute node.
It also works with user-defined XML elements, allowing for the creation of
custom attributes.
Syntax:
document.createAttribute(param1)
Parameters:
param1 Required; the name of the attribute.