Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
How to center and enlarge text using javascript?

I want to replace div content with a random text quotation (I am coding a Chrome web extension) which the code below does; but I don't know how to use javascript to manipulate the text so that I can center it, enlarge the text, bump the text down a few lines, etc. As I do not have access to the original HTML (this is for a Chrome Extension), I need to accomplish this with javascript. Is this possible?

const quotes = [
'Quotation 0.',
'Quotation 1.',
'Quotation 2.'
];
index = Math.floor(Math.random() * quotes.length);
document.getElementById('pageContent').outerHTML = quotes[index];
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

js does not cause the rendering of text, the browser interprets the html and css to render the text. You can use js to inject html and css for you desired effect. If you can not directly edit the html or css document, you can use inline stylings to create visual effects, however chrome extension do have the ability to inject css as well as js.

How about something like modification to the code you provided:

const quotes = [
  'Quotation 0.',
  'Quotation 1.',
  'Quotation 2.'
];
const index = Math.floor(Math.random() * quotes.length);
const h2 = document.createElement("h2");
h2.style.cssText = `
  text-align: center;
  font-size: 3rem;
  margin: 1rem;
`;
h2.innerText = quotes[index];

document.getElementById('pageContent').appendChild(h2);
about 4 years ago · Juan Pablo Isaza Denunciar

0

This is really a Cascading Style Sheets (CSS) question.

You can use CSS's

text-align: "center"
font-size: "130%"

I also advise you to look into what other settings font-size can have (vis-a-vis percentage). It is better if you can apply these styles on a CSS stylesheet. But if you want to do it in JavaScript, you can do

myElement.style.textAlign = "center";
myElement.style.fontSize = "130%"
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda