Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting widths of dynamic float divs

I am building a dynamic dropdown navigation.

In the dropdown there are multiple floating divs, but between each 'row of items' I have to add a horizontal divider. I can't set a static width because the text-length of the items are dynamic and may not wrap.

So I am reading each container, reading all div items, I want to read the width of the items to add the divider but can't manage it.

$('.muTopNavDropdown').each(function(i, e) {
        var iWidth = 0;
        $(this).find('.mainSubNavRowItem').each(function(ii, ee) {
        if (iWidth > maxWidth)
        alert('divide!');

            alert($(ee).width() +'-'+ $(ee).offsetWidth +'-'+ $(ee).clientWidth);

            iWidth += $(ee).width();
        });

    });

How do I read a floating div with no width value and dynamic content inside width?

like image 447
Marc Uberstein Avatar asked Sep 14 '26 00:09

Marc Uberstein


1 Answers

Your code works for me. Are your divs visible? If divs are set to display none jquery will not be able to return a width.

like image 73
Chris Marais Avatar answered Sep 16 '26 14:09

Chris Marais



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!