Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Building Javascript components with tailwind

I just want to create components with tailwind css in javascript:

I started there adding an element:

let myil = document.createElement("li", {
  onclick: 'check("5");',
  class: "text-gray-900 cursor-default select-none relative py-2 pl-3 pr-9",
  zip:"listbox-option-0",
  id: "listbox-option-5",
  role: "option",
});

to my "ul" element.

I can see the element, but no css is applied. Does tailwind not work, if the element is built with javascript?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Tailwind purges the classes you dont need. If you build an element with javascript, tailwind cannot know that you will need for example text-gray-900 so it gets purged.

If you have any JavaScript files that manipulate your HTML to add classes, make sure you include those as well

module.exports = {
  content: [
    // ...
    './src/**/*.js',
  ],
  // ...
}

You can read it here: https://tailwindcss.com/docs/content-configuration

about 4 years ago · Juan Pablo Isaza Relatório

0

The solution is most likely to use a code setup suited for tailwind. I believe quite a few JS frameworks have packages for tailwind, like react/preact, nextjs, etc. So you could use one of those, or try to customize your setup to work.

I found this in the docs: https://tailwindcss.com/docs/adding-custom-styles, maybe you can write code that registers classnames in tailwind, in some way, to prevent them from being purged?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda