I successfully changed the text color, however, I am struggling to figure out how to change the background color of the p
tag. If anyone could provide guidance on how to accomplish this, it would be greatly appreciated. Below you will find my HTML
and JS
code snippets.
function button(){
var btn = document.getElementById('btn');
btn.addEventListener('click', function onClick(event) {
// Change text color globally
document.body.style.color = 'red';
});
}
button();
<style>
p{
box-sizing: border-box;
border: 1px solid black;
height: 20px;
width: 300px;
text-align: center;
background-color: lightblue; /* Added background color style */
}
</style>
<p>Welcome To My Domain</p>
<button id="btn">Button</button>