Nuevo en JS. ¿Cómo puedo aplicar CSS a este JS Fetch para modificar la posición de prueba, la fuente? Gracias.
let file = 'art.txt'; const handleFetch = () => { fetch(file) .then((x) => x.text()) .then((y) => (document.getElementById('kdkz').innerHTML = y)); }; setInterval(() => handleFetch(), 2000); <p id="kdkz"></p>Solo agrega
#kdkz { /*styling here*/ }El navegador aplicará el estilo después de buscar.
Modifique handleFetch() a:
const handleFetch = () => { fetch(file) .then((x) => x.text()) .then((y) => { const target = document.getElementById('kdkz'); target.innerHTML = y; target.style.textAlign = 'center'; // Change the position here. }); }; O bien, puede agregar estilo fácilmente dentro del documento HTML usando la etiqueta <style> antes del <body> .
<style> #kdkz { text-align: center; /* Change the position here */ } </style>