DOM Manipulation Click Mouse Event

Advertisements 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… Read More DOM Manipulation Click Mouse Event

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

Advertisements 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… Read More What is the correct way to add an asynchronous event handler with default parameters?

How do i switch the button icon from nightmode to day mode?

Advertisements So in the below code i have linked some js/jquery to elements in my html which should be self explanatory. I have console logged each if else statement to see what the issue is and it seems to be stuck on the first if statement. function toggleDisplay() { var icon = document.getElementById(“togglebutton”); var night_icon… Read More How do i switch the button icon from nightmode to day mode?

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

Advertisements 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… Read More Find out which div was clicked and pass it to the click function handler?