This works: Event.observe(el, 'click', (function() { Element.addClassName(this, 'myClass'); } ));
This works, just not the way I want:
Event.observe(el, 'click', (function(event) { Element.addClassName(Event.element(event), 'myClass'); } ));
However, getting this to work is my issue. I still need to make the string 'myClass' definable from outside of the scope of the anonymous function. The only idea I had for this was binding, per an email Greg Hill wrote a bit back. bind() is not working... I need to be able to do something like this:
this.classString = 'myClass'; Event.observe(el, 'click', (function() { Element.addClassName(this, this.classString); }.bind(this) ));
But, that doesn't work. I need the class name that gets added to the element to be dynamic....
:\
-Greg
On Feb 9, 2006, at 11:42 PM, Jerod Venema wrote: And another reply-to-self...make that:
Event.observe(el, 'click', (function(event) { Element.addClassName(Event.element(event), 'myClass'); );
On 2/9/06, Jerod Venema <[EMAIL PROTECTED]> wrote: Probably can't use the element directly like that, but this should work:
Event.observe(el, 'click', (function(event) { Element.addClassName(event.element, 'myClass'); );
On Thursday 09 February 2006 17:23, Todd Ross wrote: > On 2/9/06, Todd Ross <[EMAIL PROTECTED] > wrote: > > Event.observe(el, 'click', function(event) { > > event = event || window.event; > > var element = Event.element(event); > > Element.addClassName(element, 'myClass'); > > }); > > > > I'm not sure if there's a more Prototype-centric way to smooth out > > retreiving the event in the handler
as for this, I believe Event.observe handles finding the proper event object for you and passes that to your function. This is what I've experienced anyways :)
Since I'm using behaviour.js and sometimes calling behaviour.apply() multiple times per page-session, I can't use Event.observe, unfortunately :( I probably can, but just don't know how, yet ;)
> Sorry ... I know it's bad form to reply to yourself, but I just had a > "duh" moment. > > This is untested, but I think this would work: > > Event.observe(el, 'click', (function(event) { > Element.addClassName(this, 'myClass'); > }).bindAsEventListener(el));
> So, you were close with your first attempts, but in order for the > 'this' to be useful to you, you need to bind it to the element (el), > not the window (the default 'this' object).
Flame me if I'm wrong, but couldn't you just skip the 'this' part and use 'el' directly?
something like: Event.observe(el, 'click', (function(event) { Element.addClassName(el, 'myClass'); );
-Jeremy
-- Jeremy Kitchen ++ [EMAIL PROTECTED]
In the beginning was The Word and The Word was Content-type: text/plain -- The Word of Bob.
_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________ Rails-spinoffs mailing list
|