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

272
Views
jQuery o vanilla JS: ¿devuelve los valores r, g & b para el color de fondo del elemento?

No estoy seguro de por qué este me persigue. Tengo una cuadrícula de tarjetas de eventos. Cada tarjeta tiene un botón con el mismo color de fondo. ¿Cómo devuelvo el valor rbg de esa clase de botón, en este ejemplo event-button ?

 <div class="event-grid"> <div class="event-card"> <button class="event-button">Buy Tickets</button> // return r, g & b values for bg color </div> <div class="event-card"> <button class="event-button">Buy Tickets</button> </div> <div class="event-card"> <button class="event-button">Buy Tickets</button> </div> <div class="event-card"> <button class="event-button">Buy Tickets</button> </div> </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si desea obtener el valor r , g , b y a valor de la definición de la clase css, puede usar la referencia getComputedStyle

Por favor, encuentre el violín de trabajo.

 document.querySelectorAll('button.event-button').forEach((button) => { button.onclick = function(e) { const styles = window.getComputedStyle(e.target); const background = styles.getPropertyValue("background-color"); const [red, green, blue, alpha] = background.replace(/^(rgb|rgba)\(/,'').replace(/\)$/,'').replace(/\s/g,'').split(','); console.log(red, green, blue); } });
 .event-button { background: rgba(255,0,0,0.3); }
 <div class="event-grid"> <div class="event-card"> <button class="event-button">Buy Tickets</button> // return r, g & b values for bg color </div> <div class="event-card"> <button class="event-button">Buy Tickets</button> </div> <div class="event-card"> <button class="event-button">Buy Tickets</button> </div> <div class="event-card"> <button class="event-button">Buy Tickets</button> </div> </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!