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

201
Views
Dropdown won't close on select (javascript)

I'm trying to create a number of dropdowns on one page that choose radio buttons based on the selection from that dropdown.

It's half working, the radio button IS changing per choice, however I can't get the dropdown to close and retain the selector when chosen. Wondering if it's to do with the JS - fiddle below

Fiddle: https://jsfiddle.net/8b069fj2/

$("input").on("change", function () {
  var inputName = this.name;
  $("#select-' + inputName + '-btn").html(this.checked ? this.value : "");
});

$(".js-option").on("click", function () {
  $(this).parent().find("ul").toggleClass("js-drop");
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you are mssing the click handler for list elements so the following worked for me:

$('input').on('change', function() {
  var inputName = this.name;
  console.log(inputName);
  var selector = '#select-' + inputName + '-btn';
  $(selector).html(this.checked ? this.value : '');
});

$('.js-option').on('click', function() {
  $(this).parent().find('ul').toggleClass("js-drop");
});

  $('li .js-option').on('click',function(){
    $(this).closest('ul').toggleClass("js-drop");
  })
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!