scripts.js code:
$(document).ready(function(){
$('#user').hover(function() {
$('#user img').attr('src', "{% static 'images/user_selected.png' %}");
}, function() {
$('#user img').attr('src', "{% static 'images/user.png' %}");
});
});
It works fine when I write it directly in my base.html file, but when I place it in an external .js file it fails to load images.
Scripts.js file loads but images do not.
base.html code:
<head>
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="{% static 'js/scripts.js' %}"></script>
...
</head>
<body>
...
<a href="{%url 'logout' %}">LOG OUT</a>
<a id="user" href="#">
<img src="{% static 'images/user.png' %}" />
<span id="user-name">{{request.user.username}}</span>
</a>
...
</body>