50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
/* window.addEventListener("load", function() {
|
|
document.getElementById("clickMe2").addEventListener("click", border);
|
|
}); */
|
|
|
|
/*function border()
|
|
{alert("elias müllbot")}; */
|
|
|
|
function highlight(){
|
|
|
|
/* const ding = document.getElementById("topTitle");
|
|
ding.style.textDecoration = "underline";
|
|
ding.style.textDecorationColor = "red";
|
|
|
|
const etwas = document.getElementById("personName");
|
|
etwas.style.textDecoration = "underline";
|
|
etwas.style.textDecorationColor = "red";
|
|
// const texts = document.querySelectorAll('*'); */
|
|
|
|
|
|
const listOfElements = document.querySelectorAll("*");
|
|
console.log(listOfElements);
|
|
console.log("hallo");
|
|
|
|
|
|
for(let elementNumber = 0; elementNumber <= listOfElements.length; elementNumber ++){ //für alle Elemente der Seite
|
|
tag = listOfElements[elementNumber]; //tag ist das Element, das gewählt ist
|
|
|
|
console.log(elementNumber, tag);
|
|
|
|
if (tag){
|
|
|
|
const hasChildren = tag.children.length > 0;
|
|
const elementText = tag.textContent ? tag.textContent.trim(): " ";
|
|
const hasText = elementText.length > 0;
|
|
|
|
if (hasChildren != true && hasText == true){
|
|
|
|
const targetWord = "die" || "Du" || "funktion";
|
|
let originalHTML = tag.innerHTML; //den ursprünglichen HTML-Inhalt speichern
|
|
|
|
const regex = new RegExp(`\\b${targetWord}\\b`, 'gi');
|
|
tag.innerHTML = originalHTML.replace(regex, `<span style="text-decoration: underline; text-decoration-color: red;">$&</span>`);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
highlight(); |