<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
Post a Comment