cero
cero

Reputation: 39

Jquery select onClick

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

Upvotes: 0

Views: 86

Answers (1)

cero
cero

Reputation: 39

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.

Upvotes: 1

Related Questions