Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:51:26+00:00 2026-05-28T01:51:26+00:00

View jsFiddle Attempting to set the min-Width of a <menu> by calculating the total

  • 0

View jsFiddle

Attempting to set the min-Width of a <menu> by calculating the total width of all the <command> elements inside of the <menu>. I tried my best to figure it out in the following jQuery:

$(document).ready(function() {
    $('menu').each(function() {

        var minWidth;

        $('menu command').each(function() {
            minWidth = minWidth + $(this).outerWidth(); 
        });

        $(this).css('min-width', minWidth);
    });
});

This is the format for the HTML:

<menu>
    <command class="less" />
    <command class="more" />

    <div class="space"></div>

    <command class="save" />
    <command class="vote" />
    <command class="send" />
</menu>

The div.space is just a seperator that I’m going to code later to split the commands across the full length.

My code currently comes up with no errors.

View jsFiddle

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:51:26+00:00Added an answer on May 28, 2026 at 1:51 am

    When defining the minWidth variable you forgot to set it to 0. You also forgot to add ‘px’ behind the number when setting the CSS. Here’s your code, working:

    $(document).ready(function() {
        $('menu').each(function() {
    
            var minWidth = 0;
    
            $('menu command').each(function() {
                minWidth = minWidth + $(this).outerWidth();
            });
    
            $(this).css('min-width', minWidth + 'px');
        });
    });
    

    http://jsfiddle.net/kkBRE/5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see this http://jsfiddle.net/yv8uw/1/ When you click View all Comments the box opens up
Please view this fiddle in IE6: http://jsfiddle.net/rS4dE/2/ Unless I add a width of 1%
I have a layout setup which can be view here: http://jsfiddle.net/Pn3ts/ It all works
Firstly could you view my outcome http://jsfiddle.net/RXnKR/ From this I decided as you click
See the following fiddle: [edit: updated fiddle => http://jsfiddle.net/NYZf8/5/ ] http://jsfiddle.net/NYZf8/1/ (view in different
View demo here: http://jsfiddle.net/55H7U/26/ Play video in firefox, when CSS overflow attribute is changed
Please view the code and gaps between the images shown here: http://jsfiddle.net/uyVZj/2/ In Firefox
Take a look at this jsFiddle Code also listed below: window.MyView = Backbone.View.extend({ ticks:
I have an Ember application with both a view and a controller: http://jsfiddle.net/gavriguy/EDr4G/ I
What I am attempting to do is when the user clicks on the View

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.