I’m sure there is someone out there who knows the answer to this, but so far I’ve been unable to find a solution…

I have a span element that contains some text, with an onclick function that takes the displayed text and allows it to be edited with a save and cancel button. Pretty straightforward stuff, but it doesn’t work fully.

The code creates the text input box and the buttons dynamically, setting the onclick for each button to the appropriate function. It then removes the onclick event from the span so the button events get seen. Once a button is pressed the functions are supposed to add back the onclick for the span – and this is where it goes wrong!

If I try and use

node.onclick = Function('textToEdit(1,2,3)');

The function is executed immediately, which isn’t ideal. I’ve tried using

node.onclick = function() { textToEdit(1,2,3); };

but that also seems to execute straight away.

So, javascript folks in the know, what am I doing wrong???