I'm creating a map; I want to add some informations to every location using Array. Ex: I have 3 divs and an Array which has three Length (informations for the divs). Now, whenever I mouse over on a div, it should compare the attribute (elID) to the Array, and get The informations like head or Paragraph out.
Ex of HTML:
<div id="container">
<div elID = "first">first</div>
<div elID = "second">second</div>
<div elID = "third">third</div>
</div>
What I've done in Javascript:
const locations = [
{"location": "first", "head":"This is first the head", "paragraph":"kommtNoch"},
{"location": "second", "head":"This is the second head", "paragraph":"kommtNoch"},
{"location": "third", "head":"This is the third head", "paragraph":"kommtNoch"} ]
const red = document.querySelectorAll('#container > div');
for(i=0; i<red.length;i++){
red[i].setAttribute('onmouseover', 'myFirstFunction(this)');
function myFirstFunction(e){
if(e.classList === locations.indexOf()){
console.log(locations[i].location);
}
I found some Answers here, but they're hard for me to understand:
Check if an array contains any element of another array in JavaScript