Hi, I have a class ''Menu'' with a method ''addItem''. The method (simplified) looks like this: addItem: function(itemId, text) { this.container.innerHTML += ''<div id="''+itemId+''">''+text+''</div>''; Event.observe(itemId, ''mouseover'', this.onMouseOverHandler.bindAsEventListener(this), false); } I call my class in the following way: var myMenu = new Menu(); myMenu.addItem(''item1'', ''Item 1''); myMenu.addItem(''item2'', ''Item 2''); myMenu.addItem(''item3'', ''Item 3''); And here comes the mystery: only the last item (item3) triggers the ''onMouseOverHandler'' listener. When I remove item3, than it''s trigged by item2 and so on... Anyone have a solution? Thank you in advance! Thomas -- Posted with http://DevLists.com. Sign up and save your mailbox.
Try this: Event.observe($(itemId),''mouseover'', this.onMouseOverHandler.bindAsEventListener(this),false); - Joe On 29 Apr 2006 20:59:24 -0000, Thomas Anderson < devlists-scriptaculous-mifkN9UeCURWk0Htik3J/w@public.gmane.org> wrote:> > Hi, > > I have a class ''Menu'' with a method ''addItem''. The method (simplified) > looks like this: > > addItem: function(itemId, text) > { > this.container.innerHTML += ''<div id="''+itemId+''">''+text+''</div>''; > Event.observe(itemId, ''mouseover'', > this.onMouseOverHandler.bindAsEventListener(this), false); > } > > I call my class in the following way: > > var myMenu = new Menu(); > myMenu.addItem(''item1'', ''Item 1''); > myMenu.addItem(''item2'', ''Item 2''); > myMenu.addItem(''item3'', ''Item 3''); > > And here comes the mystery: only the last item (item3) triggers the > ''onMouseOverHandler'' listener. When I remove item3, than it''s trigged by > item2 and so on... > > Anyone have a solution? Thank you in advance! > > Thomas > > > > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Thanks Joe, but $(itemId) behaves the same way as itemId. I''ve solved it by using Insertion.Before instead of direct innerHTML but I still don''t understand what was wrong with my code... Anyone can help me explain it? On Saturday, April 29, 2006, at 7:13 PM, Joseph Potenza wrote:>Try this: > >Event.observe($(itemId),''mouseover'', >this.onMouseOverHandler.bindAsEventListener(this),false); > >- Joe > >On 29 Apr 2006 20:59:24 -0000, Thomas Anderson < >devlists-scriptaculous-mifkN9UeCURWk0Htik3J/w@public.gmane.org> wrote: >> >> Hi, >> >> I have a class ''Menu'' with a method ''addItem''. The method (simplified) >> looks like this: >> >> addItem: function(itemId, text) >> { >> this.container.innerHTML += ''<div id="''+itemId+''">''+text+''</div>''; >> Event.observe(itemId, ''mouseover'', >> this.onMouseOverHandler.bindAsEventListener(this), false); >> } >> >> I call my class in the following way: >> >> var myMenu = new Menu(); >> myMenu.addItem(''item1'', ''Item 1''); >> myMenu.addItem(''item2'', ''Item 2''); >> myMenu.addItem(''item3'', ''Item 3''); >> >> And here comes the mystery: only the last item (item3) triggers the >> ''onMouseOverHandler'' listener. When I remove item3, than it''s trigged by >> item2 and so on... >> >> Anyone have a solution? Thank you in advance! >> >> Thomas >> >> >> >> >> -- >> Posted with http://DevLists.com. Sign up and save your mailbox. >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > > >_______________________________________________ >Rails-spinoffs mailing list >Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Posted with http://DevLists.com. Sign up and save your mailbox.
On 30 Apr 2006 00:48:52 -0000, Thomas Anderson <devlists-scriptaculous-mifkN9UeCURWk0Htik3J/w@public.gmane.org> wrote:> I''ve solved it by using Insertion.Before instead of direct innerHTML but > I still don''t understand what was wrong with my code...A.innerHTML += B; does C = A.innerHTML; A.innerHTML = "" // HERE A.innerHTML = C + B The children of A get removed. C has a string representation of them, but that does not include the event handlers. Just try it and alert() the value.
Wow, now it''s clear! Thank you a lot!! Thomas On Sunday, April 30, 2006, at 9:32 AM, Martin Bialasinski wrote:>On 30 Apr 2006 00:48:52 -0000, Thomas Anderson ><devlists-scriptaculous-mifkN9UeCURWk0Htik3J/w@public.gmane.org> wrote: >> I''ve solved it by using Insertion.Before instead of direct innerHTML but >> I still don''t understand what was wrong with my code... > >A.innerHTML += B; does > >C = A.innerHTML; >A.innerHTML = "" // HERE >A.innerHTML = C + B > >The children of A get removed. C has a string representation of them, >but that does not include the event handlers. Just try it and alert() >the value. >_______________________________________________ >Rails-spinoffs mailing list >Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs-- Posted with http://DevLists.com. Sign up and save your mailbox.
Seemingly Similar Threads
- Multiple calls from drop_receiving_element :complete
- Adding a function with default parameters into the Rcmdr menu
- Refresh a partial onClick using ajax call in rails 3.x
- prototype.js breaks treemenus from pear HTML_TreeMenu in safari
- Noob question for wxMenu.get_menu_items()