JS: how to hide elements outside click Elements
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = gb2312" />
< Title > Click a connection display layer ~ Click another area to hide the exercise by foot home </ Title >
< Style Type = "Text/CSS" >
# Mydiv {
Border : 1px solid #000000 ;
Width : 200px ;
Height : 100px ;
Background : # Cccccc ;
}
</ Style >
< Script Language = "JavaScript" Type = "Text/JavaScript" >
Function Addlistener (element, E, FN ){
If (Element. addeventlistener ){
Element. addeventlistener (E, FN, False );
} Else {
Element. attachevent ( " On " + E, FN );
}
}
Addlistener (document, " Click " ,
Function (EVT ){
VaR EVT = Window. Event ? Window. Event: EVT,
Target = EVT. srcelement | Evt.tar get;
If (Target. ID = " Showdiv " ){
Document. getelementbyid ( " Mydiv " ). Style. Display = "" ;
Return ;
} Else {
While (Target. nodename. tolowercase () ! = " Div " && Target. nodename. tolowercase () ! = " Html " ){
Target = Target. parentnode;
}
If (Target. nodename. tolowercase () = " Html " ){
Document. getelementbyid ( " Mydiv " ). Style. Display = " None " ;
}
}
})
</ Script >
</ Head >
< Body >
< Div ID = "Mydiv" Style = "Display: none ;" > < A Href = "Http://www.jb51.net" Target = "_ Blank" > Foot home </ A > </ Div >
< Input Type = "Button" Value = "Come out layer" ID = "Showdiv" />
</ Body >
</ Html >