0
I’m making a website where you’ll have as background a photo of Heisenberg saying "Say My Name" with a text input in the middle of the screen and when the user type Heisenberg the background will change to a photo of him saying You Goddam right, but I’m not getting it, how do I do this using Jquery?
$("#SayMyName").focusout( function(){
var SayMyName = $("#SayMyName").val();
if (SayMyName == "Heisenberg") {
$("body").css("background-image", "url(/myimage.jpg)");
}
else {
SayMyName = " "
}
});
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Document</title>
</head>
<body>
<form action="">
<input type="text" id="SayMyName" name="SayMyName">
<input type="submit" value="submit">
</form>
</body>
</html>
Does it have to be with Jquery? CSS is not enough?
– Augusto Vasques
no, because I need to check if the user has typed the name correctly
– Vitor Correa
I know this, I asked if the change in the back has to be done with jquery? The check can be done with vanilla javascript?
– Augusto Vasques
I prefer Jquery because that’s what I’m studying at the moment
– Vitor Correa
the error occurs initially because
url()
is a function that expects to receive a string with the path and it is receiving something that is not a string, the right would be to use simple quotes there"url('/myimage.jpg')"
this initially, then you have to check if the path is correct.– Raizant