Hi,
I'm trying to create a function that will change the <body> background color (from GIF to color) if the user types text inside <textarea>.
I'm a complete beginner so I'm a bit lost here..
I tried with something like this but it doesn't really work:
I'm trying to create a function that will change the <body> background color (from GIF to color) if the user types text inside <textarea>.
I'm a complete beginner so I'm a bit lost here..
I tried with something like this but it doesn't really work:
HTML:
<!DOCTYPE html>
<html>
<body>
<textarea class="input" id="myTextarea">
</textarea>
<script>
const textArea = document.querySelector(".input");
function myFunction() {
if ( textArea.value == "" )
{
document.body.style.backgroundImage = url('[URL]https://scx1.b-cdn.net/csz/news/800/2016/trackingwave.gif[/URL]');
}
else if (textArea != "" ) {
document.body.style.backgroundColor = "black";
}
}
myFunction()
</script>
</body>
</html>
Last edited by a moderator: