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

178
Visualizações
JQuery add attribute function is not working
$('#section_option').change(function () {
      var selectedClass = $("#section_option option:selected").val();
      if (selectedClass != 0) {
        //alert("You have selected the class - " + selectedClass);
        $("#sectionname").removeAttr("disabled");
        $("#sectionname").removeClass("disabled");
      } else if(selectedClass == 0) {
        alert("0 selected");
        $("#sectionname").addAttr("disabled");
        $("#sectionname").addClass("disabled");
      }     
    });

First portion of code i.e removing of attr and class is working fine but when i am trying to lock the input again when user switches back to option val 0, it is not happening due to some reason.

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

0

Not addAttr("disabled") is attr("disabled",true);

$('#section_option').change(function () {
  var selectedClass = $("#section_option option:selected").val();
  if (selectedClass != 0) {
    //alert("You have selected the class - " + selectedClass);
    $("#sectionname").removeAttr("disabled");
    $("#sectionname").removeClass("disabled");
  } else if(selectedClass == 0) {
    alert("0 selected");
    $("#sectionname").attr("disabled","disabled");
    $("#sectionname").addClass("disabled");
  }     
});

Or you can use prop:

$("#sectionname").prop("disabled",true);
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