Let me walk you through the JavaScript process I am working on:
When a text is entered in the input bar and submitted, the script dynamically creates a new "div" element and places the text inside it. This new div is then appended to an existing div called "list". Here is an example of how it is done:
$(".list").append('<div class="woof">' + '<div class="box">' + toAdd + '</div>' + '</div>');
The newly created .woof and .box divs are added to the existing .list div
, with the text from the input field stored in the variable toAdd
.
At the same time, the JavaScript also stores the toAdd
string in an array variable (e.g.,
var theArray = ["Meow", "Cheeseburger", "Yes"]
). The goal is to randomly select one of these strings from the array and highlight it in the HTML.
The challenge I am facing is in creating a script that can identify the randomly selected string in the HTML content. While I am able to pick a string from the array, I am struggling to highlight that specific string in the HTML list.
For instance, if the random number generator selects "Yes" from the array, I want to create a script that can locate and highlight "Yes" within the HTML div, making it stand out visually to the viewer.
So, the main issue I am encountering revolves around connecting the random selection from the array to the corresponding string in the HTML content. I hope this clarifies the problem I am trying to solve.