I want to search words in headlines of my posts and if it contains Names example: max or Marry, it should add Photo from them.
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");
}
})
it Works, but I have many Headlines in the class and it adds Pictures just to the last Elements of class.
var img = document.createElement("IMG");should be created for each element if needed.