javascript, why you can't add onClick in HTML string, before you add this HTML string to DOM?

I need something like that: function myfunc(){ const checkbocClick = () => { console.log("chceckbox click") } createElement = () => { let isChecked = (Number(addressPoiData.notSendInfoToDriver) === Number(0))? ‘checked’: "" return `<input type="checkbox" class="form-check-input" id="sent-to-driver" onClick=’checkbocClick()’ ${isChecked}>` } return createElement() } This function is imported and used in one class, where the append is. But I… Read More javascript, why you can't add onClick in HTML string, before you add this HTML string to DOM?

Get de href from each element inside a div and use it

I got following html: <div class="tmb"> <p>First element</p> <a href="location-one.html">Click me</a> </div> <div class="tmb"> <p>Second element</p> <a href="location-two.html">Click me</a> </div> <div class="tmb"> <p>Third element</p> <a href="location-three.html">Click me</a> </div> What I want to do is to make the whole .tmb-div clickable with the url from it’s a-element child. What I tried so far is: (function($) {… Read More Get de href from each element inside a div and use it

How do I make a function that checks if an element has a certain class and if true, runs a separate function?

I’m making a site for me to experiment and go out of my comfort zone and I’m trying to add a button that runs a different function based on whether or not it’s in dark or light theme using javaScript. I want it to work like this: if elementClass == "dark" run function 1 else… Read More How do I make a function that checks if an element has a certain class and if true, runs a separate function?

weird behavior of onclick – sometimes retrieves e.target.id and sometimes doesn't

I’m experiencing a weird response by my onClick event handling. I have a list of user boxes, which on click, I’m attempting to navigate the client to that specific user’s page ( as if – navigate("/farmershop/" + e.target.id) ) I am debugging by console.logg my e.target.id, I only get the id (which I attempt to… Read More weird behavior of onclick – sometimes retrieves e.target.id and sometimes doesn't

React Functional Component: onClick handler that updates state is not working

Below is my react functional component. Every 5 seconds I’m updating the time state and showing the time (via showTime()). I also have a button that, when clicked, will push the current time to the timeList state (which is an array). However so far I’m getting a bug in the handleClick function. What I want… Read More React Functional Component: onClick handler that updates state is not working

javascript function that reverts back on 2nd button click?

im a beginner to JavaScript & html, i made a simple button: <button id="button6" type="button" class="btns" onclick="LightTheme()">Light Mode</button> . this is supposed to change the page’s view to light mode, instead of dark. the script is: function LightTheme() { document.body.style.backgroundColor = "#DBE6FD"; document.getElementById(‘button_circle’).style.color = "white"; document.getElementById(‘button1’).style.color = "#47597E"; document.getElementById(‘button2’).style.color = "#47597E"; document.getElementById(‘button3’).style.color = "#47597E"; document.getElementById(‘text_p’).style.backgroundColor… Read More javascript function that reverts back on 2nd button click?

Why did my onclick attribute in input type button is not working?

Here is My code <form name="formA"> <input type="text" name="iptA" id="iptA" value="" /> <input type="button" name="btnA" id="btnA" value="Click Here" onclick="count();"/> <input type="button" name="btnClr" id="btnClr" value="Clear" onclick="clear();"/> </form> <script type="text/javascript" charset="utf-8"> var a = 0; document.formA.iptA.value = a; function count(){ a++; document.formA.iptA.value = a; } function clear(){ a = 0; document.formA.iptA.value = a; } </script> In this,… Read More Why did my onclick attribute in input type button is not working?