67
rated 0 times
[
68]
[
1]
/ answers: 1 / hits: 18451
/ 12 Years ago, thu, january 31, 2013, 12:00:00
I'm trying to do this:
<script>
var MyItem;
MyItem = new myobj('testobj');
function myobj(id)
{
var _id = id;
this.toggle = function()
{
...
}
function draw()
{
document.body.innerHTML += <a onclick=' + MyItem + .toggle();'>link</a>;
}
draw();
}
</script>
I get function is not defined, but can invoke MyItem.toggle() from console successfully. I've also tried:
document.body.innerHTML += <a onclick='(function(){ + MyItem + .toggle();})()'>link</a>;
The anchor has to be dynamically created in javascript. How do I invoke the MyItem object method toggle() from the dynamically created anchor?
ps, I'm typing js from memory, so if there are syntax errors I apologise.
More From » object