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 8307301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:29:56+00:00 2026-06-08T18:29:56+00:00

Good afternoon fellows, I’m having trouble with some jQuery-code and I can’t seem to

  • 0

Good afternoon fellows,

I’m having trouble with some jQuery-code and I can’t seem to grasp the problem.

The situation is as follows:

I’m making (based on mysql-entries) a couple of div’s. Perhaps it’s better if I show you the result first:

<div class="shipcontainer" id="shipcontainer1">
    <div class="timelinecontainer" id="timelinecontainer1">timeline--></div>
    <div class="travelsall" data-ship="1">
        <div class="travelcontainer" data-travelid="1" data-ship="1" id="travelcontainer1">
         <div class="fasecontainer" data-travelid="1" data-ship="1">
           <div class="Mobilize  travelfase" date-days="6" date-fasetravelid="1">1: Mobilize </div>
           <div class="Loading travelfase" date-days="12" date-fasetravelid="1">2: Loading</div>
           <div class="Boating travelfase" date-days="20" date-fasetravelid="1">3: Boating</div>
           <div class="Discharge travelfase" date-days="6" date-fasetravelid="1">4: Discharge</div>
        </div>
        <div class="options" id="optionstravel1" data-travelid="1">OPTIONS</div>
      </div>
    </div>
</div>

As you can see, I have a shipcontainerdiv. Within i have two child-divs (timelinecontainer and travelsall). The latter contains in this example only one “.travelcontainer”, but there will be more in the future.

This piece of code is repeated a couple of times, (I currently have two “.shipcontainers”).

What I wanted to achieve was to set the width of the div with “.travelcontainer” to the sum of the widths of the four div’s with “.travelfase”. This is my jQuery code:

var totalWidth = 0;

$(".travelcontainer").width(function () {
  var travelID = $(this).data(travelid);

  $(this).find('div[data-fasetravelid=' + travelID + ']').each(function (index, element) {
    totalWidth = $(this).innerWidth() + totalWidth;
  });

  return totalWidth;
});

Because, during it’s parsing through PHP, I gave the “.travelcontainer” a data-travelid attribute, and also it’s “.travelfase” grandchildren. I figured I could couple them together this way.

The problem is that when I have 2 shipcontainers, with both a “travelcontainer” it’s adding all values together. So travelcontainer with data-travelid=1, has the width of exactly the same as all div’s with class travelfase, instead of only the div’s with the data-fasetravelid=1 attribute.

I’ve also tried this code (which I’ve used earlier):

var widthTotal = 0;

$(".travelcontainer").width(function () {
  $(".travelcontainer > .travelfase").each(function (index, element) {
    widthTotal = $(this).innerWidth() + widthTotal;
  });
});

return widthTotal;

This also has the same effect.

Does anyone see what I’m doing wrong here?

Thanks in advance!

  • 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-06-08T18:29:57+00:00Added an answer on June 8, 2026 at 6:29 pm

    Try:

    $(".travelcontainer").each(function() {
      var totalWidth = 0;
    
      $('.travelfase', this).each(function () {
        totalWidth += $(this).width();
      });
    
      $(this).width(totalWidth);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon, I'm having a problem with a section of code I'm working on
Good afternoon, I am having a little trouble with .net's internal (System.Drawing) based MetaFile
Good afternoon, I inherited some C# code from years ago. I have refactored it
Good afternoon, I have an activity that calls another. The code is as follows:
Good afternoon! I've read some articles about domain's redemptionPeriod but still can't find a
Good afternoon, hope someone can shed some light on a strange issue that I
Good afternoon, I'm having serious troubles getting my database back up and running. I
Good afternoon, I've run into some issues trying to combine HTTP caching with Rack::Cache
Good afternoon, I have been working on a dll that can use CORBA to
Good Afternoon, I am trying to assign some variables to a listing which has

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.