Hi,
I had this code:
var newCopy = new Element('div', { 'id' : obj.id, 'class' :
'de_small' }).update(obj.innerHTML);
which worked fine but now i add this and it breaks my script...it's
hard to explain exactly how it breaks but it involves a draggable
object not being droppable anymore
var newCopy = new Element('div', { 'id' : obj.id, 'class' :
'de_small' }).update(obj.innerHTML).observe('click', deleteThis());
can i not do it like this?
on 2008-07-01 17:09
on 2008-07-01 17:29
I don't see where the new element is being inserted into the document. Is there code we're missing? -Fred On Tue, Jul 1, 2008 at 10:08 AM, elduderino <jamesfiltness@googlemail.com> wrote: > > var newCopy = new Element('div', { 'id' : obj.id, 'class' : > 'de_small' }).update(obj.innerHTML).observe('click', deleteThis()); > > can i not do it like this? -- Science answers questions; philosophy questions answers.
on 2008-07-01 17:35
HI There, Yes the new element is being inserted later ( $ (dropZoneCount.id).appendChild(newCopy);)....that's all working fine....i only posted the relevant code....the bit of code when it was working and then the same bit of code with the extra code taht breaks the script. Can you see anything wrong with it?
on 2008-07-01 21:10
Looking at this brief snippet I see one potential error, You're executing your callback, try sending just the reference.
on 2008-07-01 21:20
In other words, change:
.observe('click', deleteThis());
To:
.observe('click', deleteThis);
You're passing deleteThis() as the value of your callback, which isn't
a function, but the return value of calling it.
-Fred
on 2008-07-02 17:20
Ah What about in the event that i need to feed a parameter to the
function??
like: .observe('click', deleteThis(param));
I wouldn't mind just running the funcion from here:
var newCopy = new Element('div', { 'id' : obj.id, 'class' :
'de_small' }).update(obj.innerHTML).observe('click', function{(...)};
(so just have the function code just after click...like above) ...but
i don't know if you can do it/get the syntax right
on 2008-07-02 17:47
Just wrap in another function:
.observe('click', function(){ deleteThis(param) });
-- kangax
on 2008-07-02 17:55
Or:
.observe('click', deleteThis.curry(param));
-Fred
On Jul 2, 2008, at 10:46 AM, kangax wrote:
>
> Just wrap in another function:
>
> .observe('click', function(){ deleteThis(param) });
>
> -- kangax
--
Science answers questions; philosophy questions answers.