I want to make a thing so when I type the word "plz" into a input, a div box will appear. But I can’t quite figure it out. I think it has something to do with javascript.
My code is
<html>
<style>
.boxR{
width: 350px;
height: 350px;
background-color:black;
color:red;
font-size:100px;
font-weight:700;
visibility:hidden;
}
</style>
<body>
<center>
<br>
<div class = "boxR"><br>hello</div>
<input id = "test">
</center>
<script>
while(true){
sleep(10)
if(document.getElementById("test").value == "plz"){
document.getElementById("boxR").visibility = visible
}}
</script>
</body>
</html>
I don’t know what I did wrong?
3
Answers
At
You didn’t set the style attribute
visiblity
to visible. Change thedocument.getElementById("boxR").visibility = visible
todocument.getElementById("boxR").style.visibility = visible
Changing any element’s style in JavaScript, you must reference it like this:
element.style.attribute = value
I add sample code below.
I’ve created a snippet that demonstrates the desired behavior.
One of your problems was with not putting quotes around "visible". Another one was in trying to call
sleep
, which you can’t do because JavaScript is single-threaded and thus this would lock up the browser.