Skip to content

Category: Questions

Button value output in console.log with JS

I’m fairly new to HTML and JS. I need the value of my HTML button to show in the console.log with JS. I dont want to use onclick=”…” though. This is part of my HTML file: This is my JS file: Answer 1) You have to add event listener on the html element not on the value of that element.

Only allow one React Accordion to be expanded at once

I have an array of data that will be used to create accordions, I’d like to make it so that only one of them can be expanded at once (i.e, if the user expands accordion #1 and then #2, #1 will un-expand) I have this code: I’m quite new to React so I suspect I’ve made a mistake with the

Data defined, but return undefined

I get an error after compiling it but I have defined it and fetch the data using async await but get a TypeError: data[index] is undefined I have stuck for several hours and still come out with no solution. Furthermore, I have tried to destructed it but still get the same error. Using data.map() works, but I …

How to override div onClick event when button is clicked?

I am trying to stop the parent div from executing an onClick event when the child Delete button is clicked. I tried to implement event.stopPropogation however, it gives me an error. Answer In case anyone has the same problem as me, simply use e.stopPropogation(). This stops the click event from bubbling up to…

React setState not updating

In this code in the else block, when the setState function is called, the state doesnot change Note: Even if it is asynchronous it doesn’t change it all after a long time Could this problem be because of the ES6 destructuring of the state EDIT I logged and checked with a callback and still the state rem…