Answer the question
In order to leave comments, you need to log in
How to take the src of an image and display it as text?
Good day.
1) You need to take the src of the image and put it as text in the .text-box block by pressing the #btn button.
2) If possible, put this src of the image as a background for the box2 block.
u0763918test1.isp.regruhosting.ru
<div class="box">
<img src="https://www.englishdom.com/dynamicus/blog-post/000/001/696/1551954562_content_700x455.jpg?
1551954564616" alt="img">
</div>
<div class="text-box">src-картинки</div>
<button id='btn' type="submit">Забрать src</button>
<div class="box2"></div>
Answer the question
In order to leave comments, you need to log in
let src = document.getElementsByTagName('img')[0].src;
let button = document.getElementsByTagName('button')[0];
button.onclick = function(e) {
let box = document.querySelector('.text-box');
let box2 = document.querySelector('.box2');
box.style.background = `url(${src}) no-repeat`;
box2.innerText = src
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question