Vote count:
0
Trying to change text color and background color fot the text accordingly to what I write in the textbox. Seems to work, it shows me the color for a split of second, like a quick snap and that's it. Looked around the code a few time. Feeling lost, don't know what could be the problem.
<!DOCTYPE html>
<html>
<head>
<title>Prelab5 Ex1</title>
<style>
</style>
</head>
<body>
<h2>Prelab5 Ex1</h2>
<form method="post">
<input type="text" name="background" id="background"/><input type="submit" value="Background" onclick="changeBack();"/>
<br/>
<input type="text" name="text" id="text"/><input type="submit" onclick="changeText();" value="Text"/>
<br/>
<div id="content">Some text</div>
</form>
<script>
var DivText = document.getElementById("content");
function changeBack(){
var backColor = (document.getElementById("background").value);
DivText.style.backgroundColor= backColor;
}
function changeText(){
var textColor = (document.getElementById("text").value);
DivText.style.color = textColor;
}
</script>
</body>
Hope you can advice me some soluction.
asked 8 secs ago
Change the text color and background color through javascript
Aucun commentaire:
Enregistrer un commentaire