Reputation: 47
How to change the color of a div tag in HTML with JavaScript code
Upvotes: 0
Views: 63
Reputation: 202
<div id="myDiv">
//your code goes here
</div>
<script>
document.getElementById("myDiv").style.backgroundColor = "red";
</script>
You have to trigger this is somehow like on body load or on button click
Upvotes: 1
Reputation: 9
// selecting the html element using id
var div = document.getElementById("apple");
div.style.color = "red";
<div id="apple">
<p>some text</p>
</div>
Upvotes: 0