Ex(pseudo-code):
<ul class="menu">
<li class="extended">
<div class="columns column1">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
</li>
<li class="extended">
<div class="columns column2">
<ul>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
</ul>
</div>
</li>
</ul>
<ul class="menu">
<li class="extended">
<div class="columns column1">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
</ul>
</div>
</li>
<li class="extended">
<div class="columns column2">
<ul>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
</ul>
</div>
</li>
</ul>
And the goal is to be like this:
Item 1 | Item 6
Item 2 | Item 7
Item 3 | Item 8
Item 4 | Item 9
Item 5 | Item 10
or
Item 1 | Item 7
Item 2 | Item 8
Item 3 | Item 9
Item 4 | Item 10
Item 5 | Item 11
Item 6
Question:
I want to get the max width of column1 and column2 then add the result and set as width of main-wrapper:
totalWidth = column1 + column2
$(‘.main-wrapper’).css(‘width’, totalWidth);
My implentation:
var $listing = $(this).find('ul.menu .extended ul li');
var $col1, $col2;
// Loop through all target submenu lists
$listing.each(function(key, value) {
var $t = $(value);
if(key == 0) {
// Get the width of the first column
$col1 = $t.outerWidth(true);
} else if(key == $listing.length-1) {
// Get the width of the second column
$col2 = $t.outerWidth(true);
}
});
// Store the total width of columns in variable
var $total_width = $col1 + $col2 + 46;
// Append the width in the parent ul element
$(this).find('ul.menu').css('width', $total_width);
But my script only get the width correctly if the text has no spaces.
Here my solution to my question. Thanks guys for all the inputs.