Maybe this is a really dumb question, but I'm learning Javascript and Django and can't figure it out. I've spent a few hours on this and maybe it's a syntax error or something else.
I want to specify the source of an image in javascript and then display the image in Django HTML template. It's not working, even with simple images
Here is my javascript:
$(document).ready(function() {
var image = document.getElementById("image").src('https://res.cloudinary.com/.../{{ object.id}}');
}
Here is my image info:
<img src="#" id="image" class="mx-auto" width="250px" onerror='this.onerror = null; this.src="https://res.cloudinary.com/.../image.jpg"'/>
What am I doing wrong? It's definitely not working - the image is not showing up even when it exists. I either get the default image or no image.
The javascript is in the HTML file and this is what I have at the top of my file:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
htmlfile or its own file? When you view source, does the javascript link (with object_id) look right and you can click on it and it brings you to the image you want?var image =$("#image").attr('src','https://res.cloudinary.com/.../{{ object.id}}');