September 20th, 2012, 11:00 AM
Join Date: Sep 2012
Time spent in forums: 14 m 42 sec
Reputation Power: 0
Add event listener to a object method
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:
//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>
I want to trigger “clickFunc” each time user click on the paragraph.
Could someone tell me how to do it??
Thank you very much!!!