Thanks TJ i didnt think about it like that, the second way would work ... its oky now as i just mke it fade away after 10 seonds or something
Thanks again Alex ----- Original Message ----- From: "T.J. Crowder" <t...@crowdersoftware.com> To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com> Sent: Thursday, January 15, 2009 4:26 PM Subject: [Proto-Scripty] Re: Stoping observing Hi Alex, Apologies if I'm missing the point, but can't you use document.stopObserving[1]? [1] http://prototypejs.org/api/document/stopObserving E.g.: * * * * function showErrorDiv(msg) { var div = new Element('div', { 'id': 'errDiv', 'class': 'error' }); div.update(msg); document.body.appendChild(div); Element.observe.defer(document, 'click', removeErrDiv); } function removeErrDiv() { var div = $('errDiv'); if (div) { div.remove(); } document.stopObserving('click', removeErrDiv); } * * * * Or if you really need it to be a closure and not use a specific ID: * * * * function showErrorDiv(msg) { var div = new Element('div', { 'class': 'error' }); div.update(msg); document.body.appendChild(div); Element.observe.defer(document, 'click', function(){ try { div.remove(); } catch (e) {} document.stopObserving('click', arguments.callee); }); } * * * * The defer is there in my case because I was using a click event to trigger showErrorDiv, and of course because of bubbling that same click eventually got given to the document and removed the div right away -- deferring it lets me not worry about that. (I could have just stopped it in my click handler on my test button; either works.) FWIW, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jan 15, 2:11 pm, Jeztah <webmas...@thecarmarketplace.com> wrote: > Afternoon Guys / Gals .. > > I'm having a slight headache with stop observing .... > > i'll try to explain my code ... > > upon click of an element (in this case a form submit) my javascript > goes through some calculations and if needed calls a function to > create an error message .. this function creates a fixed position div > ontop of the page with the error message inside it. > > Now doing all this is fine but i need an > Event.observe(document,'click', function() { > removeTheElementIJustAdded();} > > on the end of it ..... > > this also works well and fine BUT !! .... do i need to stop observing > the document click else it will try to call that function every > time? .... > > P.S i cannot stop all click observers because i have more on the page > that i need to listen to .... > > All i want to do is simple .. create the div (done) and watch for a > click event on the entire document that removes it > > but it seems to be a bit headachy for me for some reason.!!! - i think > its due to me not wanting to have multiple Event.observe;s created!! > > Regards > Alex --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---