Hi there!! I have a paragraph “<p>” element and I want to attach a click event to it. But I want that event to be executed by an object method and I do not know how to do it.
This is an example of what I want to do:
I want to trigger “clickFunc” each time user click on the paragraph.
//parag.setAttribute("onclick","this.clickFunc()");//does not work
parag.setAttribute("onclick","User.prototype.clickFunc()");//does not work, username undefined
console.log("in click Func, username="+this.username);
<p id="parag">the text</p>
Could someone tell me how to do it??
Thank you very much!!!