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

137
Vistas
How do i set a button to disable with jQuery

More precisely, what is wrong with the following code, which makes it so that fields will disable int the Faculty button only if I've double-clicked the Department button first?

I've attached as a codepen for full context

$("#fac-button").on('click', function (e) {
    if($(".fName").is(":disabled")){$(".fName").prop("disabled", false)}
    if($(".lName").is(":disabled")){$(".lName").prop("disabled", false)}
    if($(".empId").is(":disabled")){$(".empId").prop("disabled", false)}
    if($(".headC").is(":enabled")) {$(".headC").prop("disabled", true)}
    if($(".startDate").is(":disabled")) {$(".startDate").prop("disabled", false)}
    if($(".stillEmployed").is(":disabled")) {$(".stillEmployed").prop("disabled", false)} 
    if($(".endDate").is(":disabled")) {$(".endDate").prop("disabled", false)}

Any help would be great, thanks

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There is NEVER a need for an if when you have something that takes a boolean.

In your case just negate the boolean

$("#fac-button").on('click', function(e) {
  ["fname", "lName", "empId", "headC", "startDate", "stillEmployed", "endDate"]
  .forEach(sel => {
    const elem = document.querySelector("." + sel);
    elem.disabled = !elem.disabled;
  })
})

You can add

$(".headC").removeAttr("disabled")

if needed

about 4 years ago · Santiago Trujillo Denunciar
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