Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
¿Cómo getComputedStyle del subelemento de div?

Lo siento de antemano por la elección de palabras de ESL. Lo que intento obtener es getComputedStyle de un h3 que es adyacente (?) o relacionado (?) a un div que tiene una clase específica (mainBook), mientras que el h3 no tiene ninguna.

Aquí hay un ejemplo del CSS:

 .mainBook { position: absolute; } .mainBook h3 { line-height: 120px; }

Sé cómo getComputedStyle de mainBook:

 const element = document.querySelector('.mainBook'); const style = getComputedStyle(element); // and then if I want: style.getPropertyValue("nameOfProperty")

Aquí está el HTML:

 <div class="mainBook"> <h3>Title</h3> </div>

No estoy seguro si esto ayuda, pero:

 const element = document.querySelector('.mainBook'); const style = getComputedStyle(element); // and then if I want: style.getPropertyValue("line-height"); // How do I getComputedStyle the h3?
 .mainBook { position: absolute; } .mainBook h3 { line-height: 120px; }
 <div class="mainBook"> <h3>Title</h3> </div>

Pero, ¿hay alguna forma de hacer lo mismo pero para h3?

¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1) Puedes obtener el elemento h3 como

 const element = document.querySelector('.mainBook h3');

y obtenga su lineHeight de línea de estilo computedStyle como:

 const style = getComputedStyle(element); let lineHeight = style.lineHeight. 

 const element = document.querySelector('.mainBook h3'); const style = getComputedStyle(element); console.log(style.lineHeight)
 .mainBook { position: absolute; } .mainBook h3 { line-height: 120px; }
 <div class="mainBook"> <h3>Title</h3> </div>

2) También puede obtener el elemento h3 del elemento mainBook como:

 const mainBookEl = document.querySelector('.mainBook'); const headingEl = mainBookEl.querySelector('h3') const style = getComputedStyle(headingEl); const lineHeight = style.lineHeight; 

 const mainBookEl = document.querySelector('.mainBook'); const headingEl = mainBookEl.querySelector('h3') const style = getComputedStyle(headingEl); console.log(style.lineHeight)
 .mainBook { position: absolute; } .mainBook h3 { line-height: 120px; }
 <div class="mainBook"> <h3>Title</h3> </div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!