I am trying to identify the span id of elements in an array based on their values. For instance, if the value in the array is "Yellow", I need to determine that the corresponding span's id is "test4". However, I am struggling to figure out how to extract the span id from the text/value within the span tags.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function doFunction(){
var myArray = ["Green", "Yellow", "Brown"];
for (i = 0; i < myArray.length; i++) {
text = myArray[i];
alert(text);
}
}
</script>
<title></title>
</head>
<body>
<span id="test1">Red</span><br>
<span id="test2">Green</span><br>
<span id="test3">Blue</span><br>
<span id="test4">Yellow</span><br>
<span id="test5">Orange</span><br>
<span id="test6">Brown</span><br>
<button name="button" onclick="doFunction()">Click Me</button>
</body>
</html>