[RESOLU] innerHTML valide XHTML 1.1

Nouveau WRInaute
Salut à tous,

J'ai un menu qui lorsqu'on passe sur un lien affiche un descriptif à un endroit de ma page. Pour cela j'ai utilisé un script tout simple :

Code:
<script type="text/javascript">
	descr=new Array;
	descr[0]='Vous êtes ici : <a href="/">Accueil</a>';
	descr[1]='<strong>ACCUEIL :</strong> Page d\'accueil';
	descr[2]='<strong>PERSO :</strong> Page avec diverses informations personnelles';
	descr[3]='etc...';
</script>

Et sur les liens j'ai mis :
Code:
<a href="/" title="Accueil du site" onmouseover="document.getElementById('navigation').innerHTML=descr[1];" onmouseout="document.getElementById('navigation').innerHTML=descr[0];">Accueil</a>

Le problème dans tout ça c'est que ma page doit être Valid XHTML 1.1... du coup j'ai des erreurs du style :

Error Line 10 column 43: document type does not allow element "a" here.
...cr[0]='Vous êtes ici : <a href="/">Accueil</a>
The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

Avez-vous une solution ? :(
 
Nouveau WRInaute
Genesys a dit:
Placer un antislash devant le slash.

Pas de changement, mais cela ne vient pas du \ mais de la balise a qui est dans le javascript. Idem pour les autres balises :

Error Line 12 column 20: document type does not allow element "strong" here.
descr[1]='<strong>ACCUEIL :</strong> Page d\'accueil avec l\'actualité sur m


Error Line 13 column 20: document type does not allow element "strong" here.
descr[2]='<strong>PERSO :</strong> Page avec diverses informations personnell

Faudrait que j'arrive à trouver un astuce ou un script de remplacement pour le résultat souhaité mais en valid XHTML 1.1
 
Nouveau WRInaute
Genesys a dit:
Pour ainsi dire, il faut échapper tous les slashs dans un javascript (balises de fin A, STRONG, etc.).

Aucun changement :
Error Line 11 column 45: document type does not allow element "a" here.

desc[0]='Vous êtes ici : <a href="\/">Accueil<\/a>';

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).
 
Nouveau WRInaute
Il suffisait d'y penser :) J'ai remplacé :

Code:
<script type="text/javascript"> 
   descr=new Array; 
   descr[0]='Vous êtes ici : <a href="/">Accueil</a>'; 
   descr[1]='<strong>ACCUEIL :</strong> Page d\'accueil'; 
   descr[2]='<strong>PERSO :</strong> Page avec diverses informations personnelles'; 
   descr[3]='etc...'; 
</script>

par :

Code:
<script type="text/javascript" src="/v8/navigation.js"></script>

en mettant le contenu dans le navigation.js. Du coup c'est bien valid xhtml 1.1 :)
 
Nouveau WRInaute
madx a dit:
Essaye
<script type="text/JavaScript">
//<![CDATA[
<!--
ton code

//-->
//]]>
</script>

Ah nickel ! ça marche bien :)
Par contre ça marche aussi bien comme ça :
Code:
<script type="text/JavaScript"> 
<!-- 
mon code 

//--> 
</script>

Donc à quoi servent les //<![CDATA[ et //]]> ?
 
Discussions similaires
Haut