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

107
Visualizações
Replace attr value using const

when I try to modify the attr of an input, for example "data-disabled-dates" replacing the content with a const, the result I get is a text with the name of the const, but not the const content, which would be the correct way to get it.

html

<input data-min-date="+1" data-disabled-dates="24/12/2021; 25/12/2021; 30/12/2021; 31/12/2021">

Javascript/Jquery

const dateObj = new Date();
jQuery("input[data-min-date='+1']").attr('data-disabled-dates','dateObj'); 

So the wrong result is:

<input data-min-date="+1" data-disabled-dates="dateObj">

The result i want (today):

<input data-min-date="+1" data-disabled-dates="16/11/2021">
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You wrapped the name of the const in quotes so it became a string.

solution:

const dateObj = new Date();
jQuery("input[data-min-date='+1']").attr('data-disabled-dates',dateObj); 

or if you really want date to be formatted like dd/MM/YYYY:

const now = new Date();
jQuery("input[data-min-date='+1']").attr(
  'data-disabled-dates', 
  `${now.getDate()}/${now.getMonth()+1}/${now.getFullYear()}`
); 
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