K
K
Kosmatos_fx2020-12-14 00:06:10
JavaScript
Kosmatos_fx, 2020-12-14 00:06:10

How to replace an image without HTML changes?

Hello! I'm a complete JS noob and need help. Googled a lot, but apparently my knowledge is not enough. The point is this. There is an image added to html and it has no id and only class. How can I use JS or jQuery to replace the image
Here is the html snippet

div style="float: left; margin-right: 10px">
<img width="50" class="user-profile-image user-default-profile-image " src="img/default_profile_50.png"></div>


Tried to assign an id with
function myFoo1(){document.getElementsByClassName("user-default-profile-image")[0].id = "defimage"; }

And replace with
$('#defimage').attr('src', '/fileservice/file/download/a/233337/sc/494/h/c803022e0f37921830b75a0d243e73e0.png')


But it doesn't come out

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question