Attribute item() Method - Change the value of a <button> element's second attribute: - Javascript DOM

Javascript examples for DOM:Attribute

Description

Attribute item() Method - Change the value of a <button> element's second attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.example {/*from w  ww  .j  a v  a2 s .  c o m*/
    color: red;
    padding: 5px;
    width: 150px;
    font-size: 15px;
}

.newClass {
    color: blue;
    padding: 15px;
    width: 250px;
    font-size: 18px;
    background-color: white;
}
</style>
</head>
<body>

<button onclick="myFunction()" class="example">Test</button>

<script>
function myFunction() {
    var a = document.getElementsByTagName("BUTTON")[0];
    a.attributes[1].value = "newClass";
}
</script>

</body>
</html>

Related Tutorials