Chosen harvesthq resize width dynamically

前端 未结 12 1609
渐次进展
渐次进展 2020-12-30 03:49

How can you have a harvesthq Chosen dropdown with a dynamic width style?

By default it has a fixed width and if you try to modify it with CSS you will have several p

12条回答
  •  遥遥无期
    2020-12-30 04:24

    this one worked for me, even with multiple select boxes on the screen:

    $(document).ready(function(){      
       resizeChosen();
       jQuery(window).on('resize', resizeChosen);
    });
    
    function resizeChosen() {
       $(".chosen-container").each(function() {
           $(this).attr('style', 'width: 100%');
       });          
    }

    Year 2019. edit: Bear in mind that this answer was made 4 years ago when jQuery was popular library and when it was widely used. My advice is to use pure JS for everything made after this year. Don't neg rep historical answers that worked at the time they were written.

提交回复
热议问题