Jquery select onClick

89 Views Asked by At

I want to add a background overlay on my webpage to darken the website when a selectbox is opened.

This needs to be triggered when the select is opened I tried using onClick but that doesn't work. onChange only works if there is something selected other than the dfault value but this is not what I want. I want it to trigger whenever the select is clicked.

See example of dimmed bg

1

There are 1 best solutions below

3
cero On

Nvm, I use select2 and I found it in their documentation:

select2:close Triggered whenever the dropdown is closed. select2:closing is fired before this and can be prevented.

select2:open Triggered whenever the dropdown is opened. select2:opening is fired before this and can be prevented.

Select 2 code used:

  $('.select2').on('select2:open', function (e) {
    $('.menu-overlay').addClass('block')
  });

Overlay beeing the div that darkens the website.