Я хочу искать слова в заголовках моих сообщений, и если он содержит пример Имена: max или Marry, он должен добавить фотографию из них.
var imageLocation = document.querySelectorAll(".summary"); // where Image should be added
var headLines = document.querySelectorAll(".ecs-thumbnail");// where my Names are.
var img = document.createElement("IMG");
headlines.forEach(function (pos){
const txt = pos.innerText;
var max = txt.includes("max");
var marry = txt.includes("marry");
if(marry === true){
pos.parentNode.childNodes[1].prepend(img);
img.setAttribute("src", "https://dev.musikzentrum-hannover.de/wp-content/uploads/marry.png");
} else if(max === true){
pos.parentNode.childNodes[1].prepend(imgAus);
img.setAttribute("src", "https://dev.musikzentrum-hannover.de/wp-content/uploads/max.png");
}
})
это работает, но у меня есть много заголовков в класс и добавляет картинки только к последним элементам класса.