Fermer un DIV quand on clique en dehors
Bonjour,
J'ai trouvé sur le net une tonne d'exemple qui me permettent de fermer un DIV quand le clique a l'extérieur de celui-ci !
Je poste ici parce que que je n'ai rien trouvé qui règle mon problème !
Voici la page qui contient mon menu : http://www.d3cup.com/toolbar.php
Mon lien est fait sur une image qui ouvre un DIV. quand on reclique sur limage, le div se referme.
A chaque fois que j'ajoute un code qui permet de fermer le DIV quand on clique a l'extérieur, le reclique sur limage pour fermer le DIV ne fontionne plus ... !!
J'ai probablement un problème a quelque part .. Je ne suis pas très bon en Javascript..
Voici mon code html pour ouvrire le DIV
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<div>
<ul>
<li id="ico" class="icon"><a href="index.php?profile=<?= $id; ?>"><img border="0" src="ico/profile.png" title="<? echo $pseudo; ?>'s profile"></a></li>
<li class="separator"> </li>
<li id="ico" class="icon"><a id="ico2" href="javascript:callplayed('played')"><img border="0" src="ico/tounoijoue.png" title="Tournaments played"></a></li>
<li id="ico" class="icon"><a id="ico3" href="javascript:callnextgame('nextgame')"><img border="0" src="ico/nextgame.png" title="Next Game"></a></li>
<li id="ico" class="icon"><a id="ico4" href="javascript:callversuschat('versuschat')"><img border="0" src="ico/versuschat.png" title="Versus Chat"></a></li>
<li id="ico" class="icon"><a id="ico5" href="javascript:callteam('team')"><img border="0" src="ico/team.png" title="Team"></a></li>
<li id="ico" class="icon"><a id="ico6" href="javascript:callfriends('friends')"><img border="0" src="ico/friends.png" title="Friends"></a></li>
<li class="chat"><?
$h1 = date("G");
$h = $h1 + 3;
$m = date("i");
$time = "$h:$m";
echo $time; ?></li>
<li id="ico" class="icon-chat"><a href="disconnect.php"><img border="0" src="ico/logout.png" title="Logout"></a></li>
<li class="chat separator"> </li>
</ul>
</div> |
Voici mon code javascript fait comme je peux..
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
function callplayed(id) {
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
document.getElementById("ico2").style.background = "#C0C0C0";
<?php if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { ?>
document.getElementById("ico2").style.paddingTop = "17px";
<?php } else { ?>
document.getElementById("ico2").style.paddingTop = "16px";
<?php } ?>
document.getElementById("ico2").style.paddingLeft = "2px";
document.getElementById("ico2").style.paddingRight = "2px";
document.getElementById("ico2").style.borderLeft = "1px solid #333333";
document.getElementById("ico2").style.borderRight = "1px solid #333333";
document.getElementById("ico2").style.borderBottom = "1px solid #333333";
document.getElementById("nextgame").style.display = "none";
document.getElementById("versuschat").style.display = "none";
document.getElementById("team").style.display = "none";
document.getElementById("friends").style.display = "none";
document.getElementById("ico3").style.background = "";
document.getElementById("ico3").style.borderLeft = "1px solid transparent";
document.getElementById("ico3").style.borderRight = "1px solid transparent";
document.getElementById("ico3").style.borderBottom = "1px solid transparent";
document.getElementById("ico4").style.background = "";
document.getElementById("ico4").style.borderLeft = "1px solid transparent";
document.getElementById("ico4").style.borderRight = "1px solid transparent";
document.getElementById("ico4").style.borderBottom = "1px solid transparent";
document.getElementById("ico5").style.background = "";
document.getElementById("ico5").style.borderLeft = "1px solid transparent";
document.getElementById("ico5").style.borderRight = "1px solid transparent";
document.getElementById("ico5").style.borderBottom = "1px solid transparent";
document.getElementById("ico6").style.background = "";
document.getElementById("ico6").style.borderLeft = "1px solid transparent";
document.getElementById("ico6").style.borderRight = "1px solid transparent";
document.getElementById("ico6").style.borderBottom = "1px solid transparent";
} else {
if (obj.style.display == ""){
obj.style.display = "none";
document.getElementById("ico2").style.background = "";
document.getElementById("ico2").style.borderLeft = "1px solid transparent";
document.getElementById("ico2").style.borderRight = "1px solid transparent";
document.getElementById("ico2").style.borderBottom = "1px solid transparent";
}
}
}
}
function callnextgame(id) {
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
document.getElementById("ico3").style.background = "#C0C0C0";
<?php if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { ?>
document.getElementById("ico3").style.paddingTop = "17px";
<?php } else { ?>
document.getElementById("ico3").style.paddingTop = "16px";
<?php } ?>
document.getElementById("ico3").style.paddingLeft = "2px";
document.getElementById("ico3").style.paddingRight = "2px";
document.getElementById("ico3").style.borderLeft = "1px solid #333333";
document.getElementById("ico3").style.borderRight = "1px solid #333333";
document.getElementById("ico3").style.borderBottom = "1px solid #333333";
document.getElementById("played").style.display = "none";
document.getElementById("versuschat").style.display = "none";
document.getElementById("team").style.display = "none";
document.getElementById("friends").style.display = "none";
document.getElementById("ico2").style.background = "";
document.getElementById("ico2").style.borderLeft = "1px solid transparent";
document.getElementById("ico2").style.borderRight = "1px solid transparent";
document.getElementById("ico2").style.borderBottom = "1px solid transparent";
document.getElementById("ico4").style.background = "";
document.getElementById("ico4").style.borderLeft = "1px solid transparent";
document.getElementById("ico4").style.borderRight = "1px solid transparent";
document.getElementById("ico4").style.borderBottom = "1px solid transparent";
document.getElementById("ico5").style.background = "";
document.getElementById("ico5").style.borderLeft = "1px solid transparent";
document.getElementById("ico5").style.borderRight = "1px solid transparent";
document.getElementById("ico5").style.borderBottom = "1px solid transparent";
document.getElementById("ico6").style.background = "";
document.getElementById("ico6").style.borderLeft = "1px solid transparent";
document.getElementById("ico6").style.borderRight = "1px solid transparent";
document.getElementById("ico6").style.borderBottom = "1px solid transparent";
} else {
if (obj.style.display == ""){
obj.style.display = "none";
document.getElementById("ico3").style.background = "";
document.getElementById("ico3").style.borderLeft = "1px solid transparent";
document.getElementById("ico3").style.borderRight = "1px solid transparent";
document.getElementById("ico3").style.borderBottom = "1px solid transparent";
}
}
}
}
function callversuschat(id) {
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
document.getElementById("ico4").style.background = "#C0C0C0";
<?php if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { ?>
document.getElementById("ico4").style.paddingTop = "17px";
<?php } else { ?>
document.getElementById("ico4").style.paddingTop = "16px";
<?php } ?>
document.getElementById("ico4").style.paddingLeft = "2px";
document.getElementById("ico4").style.paddingRight = "2px";
document.getElementById("ico4").style.borderLeft = "1px solid #333333";
document.getElementById("ico4").style.borderRight = "1px solid #333333";
document.getElementById("ico4").style.borderBottom = "1px solid #333333";
document.getElementById("nextgame").style.display = "none";
document.getElementById("played").style.display = "none";
document.getElementById("team").style.display = "none";
document.getElementById("friends").style.display = "none";
document.getElementById("ico3").style.background = "";
document.getElementById("ico3").style.borderLeft = "1px solid transparent";
document.getElementById("ico3").style.borderRight = "1px solid transparent";
document.getElementById("ico3").style.borderBottom = "1px solid transparent";
document.getElementById("ico2").style.background = "";
document.getElementById("ico2").style.borderLeft = "1px solid transparent";
document.getElementById("ico2").style.borderRight = "1px solid transparent";
document.getElementById("ico2").style.borderBottom = "1px solid transparent";
document.getElementById("ico5").style.background = "";
document.getElementById("ico5").style.borderLeft = "1px solid transparent";
document.getElementById("ico5").style.borderRight = "1px solid transparent";
document.getElementById("ico5").style.borderBottom = "1px solid transparent";
document.getElementById("ico6").style.background = "";
document.getElementById("ico6").style.borderLeft = "1px solid transparent";
document.getElementById("ico6").style.borderRight = "1px solid transparent";
document.getElementById("ico6").style.borderBottom = "1px solid transparent";
} else {
if (obj.style.display == ""){
obj.style.display = "none";
document.getElementById("ico4").style.background = "";
document.getElementById("ico4").style.borderLeft = "1px solid transparent";
document.getElementById("ico4").style.borderRight = "1px solid transparent";
document.getElementById("ico4").style.borderBottom = "1px solid transparent";
}
}
}
}
function callteam(id) {
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
document.getElementById("ico5").style.background = "#C0C0C0";
<?php if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { ?>
document.getElementById("ico5").style.paddingTop = "17px";
<?php } else { ?>
document.getElementById("ico5").style.paddingTop = "16px";
<?php } ?>
document.getElementById("ico5").style.paddingLeft = "2px";
document.getElementById("ico5").style.paddingRight = "2px";
document.getElementById("ico5").style.borderLeft = "1px solid #333333";
document.getElementById("ico5").style.borderRight = "1px solid #333333";
document.getElementById("ico5").style.borderBottom = "1px solid #333333";
document.getElementById("nextgame").style.display = "none";
document.getElementById("versuschat").style.display = "none";
document.getElementById("played").style.display = "none";
document.getElementById("friends").style.display = "none";
document.getElementById("ico3").style.background = "";
document.getElementById("ico3").style.borderLeft = "1px solid transparent";
document.getElementById("ico3").style.borderRight = "1px solid transparent";
document.getElementById("ico3").style.borderBottom = "1px solid transparent";
document.getElementById("ico4").style.background = "";
document.getElementById("ico4").style.borderLeft = "1px solid transparent";
document.getElementById("ico4").style.borderRight = "1px solid transparent";
document.getElementById("ico4").style.borderBottom = "1px solid transparent";
document.getElementById("ico2").style.background = "";
document.getElementById("ico2").style.borderLeft = "1px solid transparent";
document.getElementById("ico2").style.borderRight = "1px solid transparent";
document.getElementById("ico2").style.borderBottom = "1px solid transparent";
document.getElementById("ico6").style.background = "";
document.getElementById("ico6").style.borderLeft = "1px solid transparent";
document.getElementById("ico6").style.borderRight = "1px solid transparent";
document.getElementById("ico6").style.borderBottom = "1px solid transparent";
} else {
if (obj.style.display == ""){
obj.style.display = "none";
document.getElementById("ico5").style.background = "";
document.getElementById("ico5").style.borderLeft = "1px solid transparent";
document.getElementById("ico5").style.borderRight = "1px solid transparent";
document.getElementById("ico5").style.borderBottom = "1px solid transparent";
}
}
}
}
function callfriends(id) {
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
document.getElementById("ico6").style.background = "#C0C0C0";
<?php if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { ?>
document.getElementById("ico6").style.paddingTop = "17px";
<?php } else { ?>
document.getElementById("ico6").style.paddingTop = "16px";
<?php } ?>
document.getElementById("ico6").style.paddingLeft = "2px";
document.getElementById("ico6").style.paddingRight = "2px";
document.getElementById("ico6").style.borderLeft = "1px solid #333333";
document.getElementById("ico6").style.borderRight = "1px solid #333333";
document.getElementById("ico6").style.borderBottom = "1px solid #333333";
document.getElementById("nextgame").style.display = "none";
document.getElementById("versuschat").style.display = "none";
document.getElementById("team").style.display = "none";
document.getElementById("played").style.display = "none";
document.getElementById("ico3").style.background = "";
document.getElementById("ico3").style.borderLeft = "1px solid transparent";
document.getElementById("ico3").style.borderRight = "1px solid transparent";
document.getElementById("ico3").style.borderBottom = "1px solid transparent";
document.getElementById("ico4").style.background = "";
document.getElementById("ico4").style.borderLeft = "1px solid transparent";
document.getElementById("ico4").style.borderRight = "1px solid transparent";
document.getElementById("ico4").style.borderBottom = "1px solid transparent";
document.getElementById("ico5").style.background = "";
document.getElementById("ico5").style.borderLeft = "1px solid transparent";
document.getElementById("ico5").style.borderRight = "1px solid transparent";
document.getElementById("ico5").style.borderBottom = "1px solid transparent";
document.getElementById("ico2").style.background = "";
document.getElementById("ico2").style.borderLeft = "1px solid transparent";
document.getElementById("ico2").style.borderRight = "1px solid transparent";
document.getElementById("ico2").style.borderBottom = "1px solid transparent";
} else {
if (obj.style.display == ""){
obj.style.display = "none";
document.getElementById("ico6").style.background = "";
document.getElementById("ico6").style.borderLeft = "1px solid transparent";
document.getElementById("ico6").style.borderRight = "1px solid transparent";
document.getElementById("ico6").style.borderBottom = "1px solid transparent";
}
}
}
} |
Merci d'avance !