Using setNamedItem

Example of document.getElementById("rnd").attributes.setNamedItem()

by Terrance Smith

HTML

<input type="button" id="rnd" value="random button" />
<input type="button" onclick="disableStuff();" value="disable" />

JavaScript

var disableStuff = function() {

    alert("TEST");
    var myAttrib = document.createAttribute("disabled");
    myAttrib.value = "disabled";
    document.getElementById("rnd").attributes.setNamedItem(myAttrib);
    var lenStuff = document.getElementById("rnd").attributes.length;
    //alert(document.getElementById("rnd"));
    //alert(document.getElementById("rnd").attributes.length);
    for (var i = 0; i < lenStuff; i++) {
        alert("object=" + document.getElementById("rnd").attributes[i]);
        alert("object name =" + document.getElementById("rnd").attributes[i].name);
        alert("object value =" + document.getElementById("rnd").attributes[i].value);
    }


    alert("object name =" + ("disabled"));
    //document.getElementById("rnd").attributes.setNamedItem("disabled") = "disabled";
    //alert(document.getElementById("rnd").attributes.setNamedItem("disabled"));
}