I have a code of jQuery and HTML. The code is suppose to enable the user to change text color when clicking and also choose the color that the text should be changed to. However, I'm having a bit of trouble. When I write blue in the textarea, it always change the text color to black. The second problem is that when I click "Show me the color of the text" it shows color with rgb. Is there any way to make it show the color's name?
Here is the code:
<!DOCTYPE html>
<html>
<head>
<title>Change Color of Text</title>
<script src="jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function () {
var TextColor = $("#text").css("color");
var ColorToChangeTo = $("#ColorToChange").text();
$("#GetColor").click(function () {
$("#ShowColor").text("The text color is " + TextColor);
});
$("#ChangeColor").click(function () {
$("#text").css("color", ColorToChangeTo);
});
});
</script>
</head>
<body dir="ltr" style="font-family: calibri;">
<center>
<div id="text" style="color: red;">
Hello, I am a text.
<br>Click the button below to see what is my color. If you want to change my color,
<br>enter the color that you want me to be displayed in and push the button "Change text color!"
</div>
<input type="button" id="GetColor" value="Show me the text's color!" />
<br>
<div id="ShowColor"></div>
<input type="text" id="ColorToChange" />
<br>
<input type="button" id="ChangeColor" value="Change text color!" />
</center>
</body>
</html>