<div id="contentContainer">
<h1>First Page</h1>
<section id="mainSection">
<p>Lorem ipsum dolor sit amet</p>
<ul>
<li><a href="#">Black world</a></li>
<li><a href="#">White world</a></li>
<li><a href="#">666 world</a></li>
</ul>
</section>
</div>
<button id="changeTextContent">Change Text</button>
function modifyContent() {
var content = document.getElementById("contentContainer").innerText;
var newContent = "";
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var upperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numbers = "0123456789";
function isLowercase(char) {
return char >= "a" && char <= "z";
}
function isUppercase(char) {
return char >= "A" && char <= "Z";
}
function isNumber(char) {
return char >= "0" && char <= "9";
}
for (var i = 0; i < content.length; i++) {
if (isLowercase(content.charAt(i))) {
newContent += alphabet[Math.floor(Math.random() * alphabet.length)];
}
else if (isUppercase(content.charAt(i))) {
newContent += upperAlphabet[Math.floor(Math.random() * alphabet.length)];
}
else if (isNumber(content.charAt(i))) {
newContent += numbers[Math.floor(Math.random() * numbers.length)];
}
else {
newContent += content.charAt(i);
}
}
for (var j = 0; j < content.length; j++) {
content = content.replace(content[j], newContent[j]);
}
document.getElementById("contentContainer").innerText = content;
}
I am looking to create a JavaScript function that will randomly change every character inside the #contentContainer without affecting its style. This function should be triggered by clicking on the #changeTextContent button. I have tried writing a function for this purpose but it's not working as expected. Any assistance would be greatly appreciated.