Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!