0

Allow me to explain. I am trying to change a style property with JavaScript, like this:

var cool = "color";
document.getElementById("thisendshereandnow").style.cool = "red";
//This should set the text color to red.

This does not work, and I think from that you get what I am trying to do here. I tried this:

<!DOCTYPE html>
<html>
<body>
<h1 id="okay">The Element Object</h1>

<script>
var still = eval("color");
document.getElementById("myH1").style.still = "red";
</script>

</body>
</html>

this:

<!DOCTYPE html>
<html>
<body>
<h1 id="okay">The Element Object</h1>

<script>
var still = color;
document.getElementById("myH1").style.still = "red";
</script>

</body>
</html>

and this:

<!DOCTYPE html>
<html>
<body>
<h1 id="okay">The Element Object</h1>

<script>
var still = "color";
document.getElementById("myH1").style.still = "red";
</script>

</body>
</html>

but I either get an error or it just does nothing at all.

I was expecting it to change the color of the text. As you know the text color's property name is "color". I told it that I wanted to change the "color" property in the variable (style.still,var still = "color"). It either gives me an error or just doesn't do anything.

James
  • 9
  • 2

0 Answers0