I have been trying to add src to the image for a long time, but nothing works for me =(
How to create js src for an image? Image tag and class are there, but its src is not?
let child_block = document.querySelector('.child_block');
let xep = document.createElement('img');
xep.className = 'img_s';
child_block.prepend(xep);
body{
display:grid;
place-items:center;
user-select:none;
}
.main_block{
display:grid;
place-items:center;
border:1px solid black;
width: 50%;
height:500px;
margin:50px;
}
.img_s{
width:100%;
border:1px solid red;
}
.child_block{
width:50%;
height:50%;
}
<div class = "main_block">
<div class = "child_block">
</div>
</div>
>Solution :
It should be xep.src = "https://example.com"