jquerycssjquery-select2ui-select2

How can I get the height of select2 drop-down?


I am trying to get select2 drop-down actual rendered height, but:

If i use something like this:

$('#my-input-s2').on('select2-open', function() {
    var height = $(".my-dropdown").first().height()
    console.log(height)
  })

The result is always 29

And when i use this(because select2 is not fullly open because of reading remote data:

 $('#my-input-s2').on('select2-open', function() {
    var height = setTimeout($(".my-dropdown").first().height(),0)
    console.log(height)
  })

I result is gradually increasing value on every open of select2 (eg. 102, then 109, then 114)

But I need to determine the height of dropdown when the select2 is fully open * edit (fully open = when the openning is done) Thanx for your answers


Solution

  • My solution:

    Hang it to another event:

    select2-highlight Fired when a choice is highlighted in the dropdown.

    $('#my-input-s2').on('select2-highlight', function() {
                var height = $(".my-dropdown").height()
        })