[Proto-Scripty] Re: Safe hiding of a DOM element
Thanks for all your advices. $$('#pleaseWait').invoke('hide'); I do like this one, even if I am not sure why it would be a bad practice to have failsafe functions (I said functions, not methods :o) ). It is common in C++ to check if a pointer is null before freeing it. I don't see any difference with this case, but I'll be happy with the $$ ('#...) solution. Just to be clear, it is not that invoke is null-safe, but it will just invoke hide method with all elements of the enumerable, which will happen to be empty if the DOM element doesn't exist (so, hide will not be called at all). I did thought to the same kind of solution using $ ('pleaseWait','xx').invoke(hide) ('xx' being a non-existing id) but I do prefer Justin's. Eric -justin --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Safe hiding of a DOM element
if($('pleaseWait')) $('pleaseWait').hide(); This is a classic coding issue. I disagree with you - in PHP I have strict warnings on all the time so I'm always testing whether a variable is set before accessing it. It's just a much safer way to write code. On Oct 16, 11:34 am, Eric [EMAIL PROTECTED] wrote: Hi, I am slowly introducing prototype in a plain JS application, and I was looking for a way to replace the following piece of code: var pleaseWait = document.getElementById('pleaseWait'); if(pleaseWait) { pleaseWait.style.display='none'; } No rocket science here: if the processing was long enough to trigger the please wait screen (which is a P tag here), it is hidden. I did notice that this would NOT be the same than: $('pleaseWait').hide(); ...since the later would fail if for some reason the DOM object has not been created. However, I was expecting that: Element.hide('pleaseWait'); ... would be safe... but it isn't :o( Is there a clean prototypish way to do this? Wouldn't it be more convenient if the syntactic-sugar-free version of Element's methods were null-proof safe Eric --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---