set and get attribute in javascript

<html>
<head>
<title>set and get attribute in javascript</title>
</head>
<body style="background:lightgray">
<p>Click the button to test:</p>
<button onclick="getBackground()">Get background</button>
<button onclick="setBackgroundAsRed()">Set background as red</button>
</br>
<textarea style="width: 400px;height: 200px;"id="demo"></textarea>
<script>
function getBackground() {
 document.getElementById("demo").innerHTML =document.body.getAttribute("style");
}
function setBackgroundAsRed() {
 document.body.setAttribute("style","background:red");
}
</script>
</body>
</html>

Comments

Popular posts from this blog

How to write data into a excel file using vbscript

Format date as yyyy-mm-dd using vbscript