navigateur pour cacher un objet
Bonjour,
j'ai trouvé un script qui me permet de cacher ou afficher un élément. Il marche bien sous firefox mais pas sous ie. Comment faire pour que cela marche correctement de partout ?
Voici le script:
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
|
<script type="text/javascript">
Visible = false; // LE COMPOSANT A AFFICHER EST CACHE
function AfficherOuCacher(obj)
{
if (Visible == false) // SI L'OBJET N'EST PAS VISIBLE
{
Afficher(obj) // RENVOIE A LA FONCTION AFFICHER
}
else // SINON
{
Cacher(obj) // RENVOIE A LA FONCTION CACHER
}
}
function Afficher(obj)
{
var id = 'boutton'+obj;
document.getElementById(obj).style.display = ''; // AFFICHE LE COMPOSANT
document.getElementById(id).innerHTML = '<a onclick="AfficherOuCacher();" style="cursor:pointer;" id="'+id+'"><em><strong>Masquer les informations</strong></em></a>'; // CHANGE "AFFICHER" EN "CACHER"
Visible = true; // OBJET EST MAINTENANT VISIBLE
}
function Cacher(obj)
{
var id = 'boutton'+obj;
document.getElementById(obj).style.display = 'none'; // CACHE LE COMPOSANT
document.getElementById(id).innerHTML = '<a onclick="AfficherOuCacher();" style="cursor:pointer;" id="'+id+'"><em><strong>+ d\'informations</strong></em></a>'; // CHANGE "CACHER" EN "AFICHER"
Visible = false; // OBJET EST MAINTENANT CACHE
}
</script> |
Je l'appelle comme ceci:
Code:
1 2 3 4 5 6 7 8
|
<div > Mon texte d'intro</div>
<div >
<em><a id="boutton1" style="cursor:pointer;" onclick="AfficherOuCacher('1');"><strong>+ d'informations</strong></a></em></div>
<div id="1" style="display:none; background-color:#f7f7f7">
<div>Le texte a afficher</div>
</div> |
Comment régler mon soucis svp ?