Answer the question
In order to leave comments, you need to log in
How to find an image in the DOM with a certain alt using JS?
Hello.
Tell me in more detail, please, how to check if an image with a specific alt is present in the document (for example, alt="picture"
) and, if so, add a class to a certain element and put this image as the background of this element?
For example:
<article class="article-picture" style="background-image:url('путь до изображение согласно src');">
<h1>Заголовок</h1>
<p>Какой-то текст</p>
<img src="путь до изображения" alt="picture">
<p>Какой-то текст</p>
</article>
alt="picture"
to the element , and the image itself is set as the background.
In addition, the image from the text itself must be removed. To end up like this:article
article-picture
<article class="article-picture" style="background-image:url('путь до изображение согласно src');">
<h1>Заголовок</h1>
<p>Какой-то текст</p>
<p>Какой-то текст</p>
</article>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question