Relative Content

Tag Archive for javascript

Clicked event set for multiple block works only once

I have this function to get data from an API, then I create a and set the data into that . After that, for each <div> I created, I set a “click” event for that .
The code worked fine for the first time I clicked a <div>, but after that, the “click” event cannot be triggered anymore, I haven’t found the reason, can someone help me?
Thank you, below is the src:

Clicked event set for multiple block works only once

I have this function to get data from an API, then I create a and set the data into that . After that, for each <div> I created, I set a “click” event for that .
The code worked fine for the first time I clicked a <div>, but after that, the “click” event cannot be triggered anymore, I haven’t found the reason, can someone help me?
Thank you, below is the src:

This code changes the style of a targeted element in the console debug but does not change it in the DOM

`let html function display(array){ tasksList.innerHTML = ” html = ” array.forEach(elm=>{ html += `<li> <span id=”${elm.id}” class=”${elm.class}”>${elm.title}</span> <p >${elm.desc}</p> <div> <button id=”${elm.id}” class=”done-task”>Done</button> <button id=”${elm.id}” class=”delete-task”>Delete</button> <button id=”${elm.id}” class=”edit-task”>Edit</button> </div> </li>` tasksList.innerHTML = html }) } tasksList.addEventListener(‘click’, (e)=>{ if(e.target.tagName == ‘SPAN’){ console.log(e.target.nextElementSibling.tagName) e.target.nextElementSibling.classList.toggle(‘desc’) e.target.style.color = ‘red’ console.log(‘Changed color to red for’, e.target.nextElementSibling); } }) this […]