I would like to pass an object as parameter to an Onclick function inside a string. Something like follwing:
function myfunction(obj,parentobj){
var o=do
The above example does not work because the output of obj
to text is [Object object]
, so essentially, you are calling someListener([Object object])
.
While you have the instance of the element in o
, bind to it's click using javascript:
function myfunction(obj,parentobj){
var o=document.createElement("div");
o.innerHTML='';
o.onClick = function () {
someListener(obj)
}
parentobj.appendChild(o.firstChild);
}
I have created a working fiddle for you here: JSFiddle