I’m a novice at jQuery and I don’t understand why the image displays, but it doesn’t fade in as the jQuery documentation suggests.
<!DOCTYPE HTML>
<html lang='en'>
<head>
<meta charset="UTF-8">
<title>slide show test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<img id="image" alt="slide" style="opacity:0.5;"/>
<script>
var x="tiananmen-square-600.webp";
$("#image").attr('src', x, function() {
$("#image").fadeIn( "slow");
});
</script>
</body>
</html>
Help, please.
2
Answers
I got it to work by removing the opaque styling in the img tag and replacing the jQuery code with this:
.attr() doesn’t accept a 3rd parameter.
I think you want something like this
That is
#image
elementsrc
attribute