Good point. I'm having a hard time coming up with a really layout- 
agnostic method for fixing this case. There's an example I saw  
elsewhere on this list that uses Event.findElement to do this:

        document.observe('click', function(event) {
            if (event.findElement('#nav')) $('nav').hide();
        });

But note that the argument to findElement is a full CSS id, not an  
element like P or DIV, as the documentation for findElement  
signifies. I have not read the source, so I'm not sure what exactly  
is going on in this function.

So while it seems to work here, this might just be a fluke. Also,  
this works fine for a hard-coded ID, but if you want it to be more  
flexible, and use less code, it's going to take some work to port to  
a better code model.

Best to look at the source, and see if there's something in there you  
can use.

Walter

On Oct 13, 2008, at 3:42 PM, poncjusz wrote:

>
> Thanks for advances.
>
> Walter your I think that your solution is the best but what if my
> toggled element contains another elements ie.
> <div id="test">
>     <img src=".... />
>    <a href="#">[...]
> </div>
> then when I clicked on img result of:
>         var elm = $('test');
>         if(evt.element() == elm)
> will be false
>
>
> On 13 Pa┼║, 15:44, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
>> Observe document.click, and filter out events that do not include the
>> item in question.
>>
>> document.observe('click', function(evt){
>>         var elm = $('yourElement');
>>         if(evt.element() != elm)
>>         elm.hide();
>>
>> }
>>
>> Walter
>>
>> On Oct 12, 2008, at 6:02 PM, poncjusz wrote:
>>
>>
>>
>>> Hi,
>>
>>> I'm toggling element (show/hide) by giving specific class name
>>> (.visible) but how could I make an effect that when I click  
>>> everywhere
>>> EXCEPT this toggled element, it disappear?
>>
>>> thanks in advanced
>>> Tom
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to