I am a newbie to the whole html,css and javascript world. i am required to create a button which changes the color of a text in a span based of the value that is written within a textbox.
This is what i managed to write so far:
function changeColor() {
var span = document.querySelector("span");
if (span = 'purple') {
span.style.color = 'purple';
}
}
.color {
color: white;
background-color: black;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
}
.purple {
background-color: purple;
}
<form>
<span>This text changes color</span>
<div>
<input type="text" value="Type your input here">
</div>
<div>
<input type="button" value="Add Color" onclick="changeColor()">
<input type="button" value="Clear all colors" onclick="ClearColors()">
</div>
</form>
<script type="text/javascript" src="Homework3.js"></script>