How to add onclick to a html element dynamically using javascript
add an eventlistener to the element which has a defined function to call :
elem.addEventListener("click", func, false); //where func is your function name
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
The best way which i found out for myself is like below.
const li = document.createElement('li');
li.innerText = "client";
li.id ="key";
li.className = "client-class";
li.setAttribute("onclick","valid;");