A
A
Andress842021-06-26 12:16:26
JavaScript
Andress84, 2021-06-26 12:16:26

Closing one element when another is clicked?

Good day. There are two two drop-down lists, and I can't figure out how to make it so that when you click on one, the other list closes.

$(function(){
    $('.selected').click(function(){
        $('.option-list').slideToggle(200);
        $('.select').toggleClass('select-active');
    });
    $('.option').click(function(){
      select_val = $(this).attr('data-select-val');
      select_div = $(this).parent().parent();
      $(select_div).children('.selected').html($(this).html());
      $(select_div).children('input').val(select_val);
      
      $('.option-list').slideToggle(200);
      $('.select').toggleClass('select-active');
    });
  });

  $(function(){
    $('.selected-two').click(function(){
        $('.option-list-two').slideToggle(200);
        $('.select-two').toggleClass('select-active-two');
    });
    $('.option-two').click(function(){
      select_val = $(this).attr('data-select-val');
      select_div = $(this).parent().parent();
      $(select_div).children('.selected-two').html($(this).html());
      $(select_div).children('input').val(select_val);
      
      $('.option-list-two').slideToggle(200);
      $('.select-two').toggleClass('select-active');
    });
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kryamk, 2021-06-26
@kryamk

when clicking on one .slideUp() and removeClass() on the other

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question