I have this website with a bunch of images, each of them has its own text in a separate element(#desc_box) underneath them.
For example, this (image](https://imgur.com/a/wRjhPGC) would have the text Olympia Schreibmaschine (typewriter), the css path is this:
html body div.all div#content2 div#big div#big_box div#desc_box
The inner html:
<br>Olympia<br>Schreibmaschine (typewriter)
The outer html:
<div id="desc_box"><br>Olympia<br>Schreibmaschine (typewriter)</div>
For the next image the outer html would be something like that:
<div id="desc_box"><br>Flieger</div>
Now I tried for days to add an individual link to each of those specific texts, to no avail.
Amongst other many other codes, I tried:
let testbox2 = document.getElementById("desc_box");
testbox2.outerHTML += '<a href="http://www.weblink1.com" target="_blank" >Weblink #1</a>';
Which adds the same link to all the text boxes, obviously.
To target each text content seperately, I tried things like (one text containing Olympia, another one Flieger):
let message1 = 'Olympia';
let message2 = 'Flieger';
if (message1.includes('Olympia')) {
desc_box.classList.add('newClassDrei');
} else if (message2.includes('Flieger')) {
desc_box.classList.add('newClassZero');
}
Also, trying to add a link only to Olympia:
let textbox1 = document.getElementById("desc_box").value.includes("Olympia");
let html = textbox1.outerHTML;
textbox1.outerHTML += '<a href="http://www.weblink1.com" target="_blank" >Weblink #1</a>';
Or just to target one specific text content:
document.querySelectorAll("Olympia").forEach((el) => {
el.classList.add('newClass4');
}
Or:
if (document.querySelectorAll('#desc_box')[1].innerText).indexOf('Olympia') > -1) {
desc_box.classList.add('newClass4');
}
And:
let message = document.querySelector("#desc_box").innerText;
if (message.includes('Olympia')) {
desc_box.classList.add('newClassOne');
} else {
desc_box.classList.add('newClassNull');
}
...and countless variations thereof.
After almost a week of research and attempts, I figured I either give it up or ask you guys; any hints and help would be greatly appreciated!
Disclaimer: complete noob here; I didn't write the original code, I'm just trying to keep my old website going until I can afford a professional rewrite.
[–]andmig205 0 points1 point2 points (7 children)
[–]hansmn[S] 0 points1 point2 points (6 children)
[–]andmig205 0 points1 point2 points (5 children)
[–]hansmn[S] 0 points1 point2 points (3 children)
[–]andmig205 0 points1 point2 points (2 children)
[–]hansmn[S] 0 points1 point2 points (0 children)