DOM Manipulation Click Mouse Event

I was trying to change the color of the background of the web page with a mouse click, below are the lines for the same. let bodyvar = document.querySelector(‘body’); bodyvar.addEventListener(“click”,generate); function generate(){ bodyvar.style.backgroundColor = “red”; } When I test individual lines in console it is selecting the body and the function and everything works correctly… Read More DOM Manipulation Click Mouse Event

What is the correct way to add an asynchronous event handler with default parameters?

I registered a ‘click’ event listener fetchAsync to the first button labelled Fetch async. The event listener performs an HTTP POST using the Fetch API and reports the status. This seems to work correctly. The second button labelled Fetch async with default parameters is almost identical except that the event listener fetchAsyncDefault contains default parameters… Read More What is the correct way to add an asynchronous event handler with default parameters?

Find out which div was clicked and pass it to the click function handler?

I’m adding a list of child divs (cards) by looping through an array. I want to create an onclick event listener for each child div (card) of parent div (board). $.each(cardArray, function(i,value){ if(i<9){ var tCard = $(‘<div class=”cardContainer” title=”‘+cardArray[i][‘name’]+'” data-id=”‘+i+'”>’+cardArray[i][‘damage’]+'</div>’) $(“#area_myCards”).append(tCard) } }); $(“#area_myCards > .cardContainer”).on(‘click’,cardClick()) <div id=”area_myCards”></div> but I’m unsure how to find out… Read More Find out which div was clicked and pass it to the click function handler?