<! Doctype html >
< Html >
< Head >
< Meta Charset = "UTF-8" />
< Title > Close Div elsewhere </ Title >
</ Head >
< Body >
< Input Type = "Text" Value = "" ID = "TF" />
< Div Style = "Width: 400px; Height: 200px; Border: 1px solid #000; display: none" ID = "Con" >
< P > 1111 </ P >
< P > < Span > 2222 </ Span > </ P >
< P > < A Href = "#" > 3333 </ A > </ P >
</ Div >
< Script >
Function E (OBJ ){ Return Document. getelementbyid (OBJ )}
E ( ' TF ' ). Onclick = Function (Event ){
E ( ' Con ' ). Style. Display = ' Block ' ;
Stopbubble (event );
Document. onclick = Function (){
E ( ' Con ' ). Style. Display = ' None ' ;
Document. onclick = Null ;
}
}
E ( ' Con ' ). Onclick = Function (Event ){
// Only the upward bubble is blocked, but the downward capture is not blocked. Therefore, you can still execute this function when you click the internal object of con.
Stopbubble (event );
}
// Blocking the bubble Function
Function Stopbubble (e ){
If (E && E. stoppropagation ){
E. stoppropagation (); // W3C
} Else {
Window. event. cancelbubble = True ; // IE
}
}
</ Script >
</ Body >
</ Html >