This seems like it should be an easy fix. The code lets the user click on either a header, paragraph, or image and identifies what type the element is. It works but then gets stuck in an infinite loop. It appears to be continuing to try and run the same code. I read A LOT of similar questions but the suggestions to use .one or other methods haven't worked.
$(document).ready(function() {
const elementsToMatch = ['h1', 'p' , 'img']
const elementsMessage = ['This is a heading', 'This is a paragraph' , 'This is an image']
$('*').click(function(e) {
const target = $(e.target)
elementsToMatch.forEach(function(element, index) {
if (target.is(element, index)) {
alert(elementsMessage[index]);
};
});
});