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

207
Vistas
dynamic generation of themes list for a theme switcher

I am using sass to compile a set of themes and js/jquery to switch those themes from the select html tag. My sass mixin is written to compile each theme into the following format:

:root[data-theme=theme-light] {
    // css variables here
}
:root[data-theme=theme-dark] {
    // css variables here
}

Currently I have a number of different themes (about 8). I am hard coding each theme into my html select-option tag, as follows:

Example of select:


            <select id="theme-switcher" onChange="setTheme(this)">
                <option value="light">Light</option>
                <option value="dark">Dark</option>
                <option value="clean1">Clean 1</option>
                <option value="clean2">Elegant</option>
                <option value="simple">Simple</option>
                <option value="jldn">JLDN</option>
                <option value="busy">Busy</option>
                <option value="system">System</option>
            </select>

I have looked into using jquery to select all root elements in the css ruleset, then looping through them to get the value of 'data-theme', but I can't quite get it. I am using the $(':root[data-theme^="theme"]') selector, but this seems to not return anything.

I need a way, if possible, to dynamically create the theme list, to prevent hard coding the themes. This will allow time saving and ease of use when adding new themes in my sass file.

about 4 years ago · Juan Pablo Isaza
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