matchMedia et changement contenu texte fichier html
Bonjour à tous,
Je n'arrive pas à utiliser matchMedia dans le corps du html pour proposer des contenus texte différents selon s'il s'agit d'une consulation smartphone, tablette ou web.
Exemple :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<body>
<script>
if (window.matchMedia("(min-width: 600px)").matches) {
<div>
<h1>Contenu minWidth 600</h1>
<p>cool content</p>
</div>
} else {
<div>
<h1>Contenu X</h1>
<p>oldStyle content</p>
</div>
}
</script>
</body> |
Y a-t-il une façon particulière de formater le contenu html dans une balise script ?
Merci par avance !
Bonne journée.