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

  • Home
  • SEARCH
  • 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 3343644
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:58:42+00:00 2026-05-18T00:58:42+00:00

I have a bunch of divs that the user can create and which represent

  • 0

I have a bunch of divs that the user can create and which represent messaging boxes. When a user clicks on one of their friends’ names a box is created. I have been able to make it so that when a new box is created it is positioned the right distance away, but I have not been able to figure out how to make it so that when a box is removed, the other boxes are moved over to fill the void and make space for new boxes. I know I need to use foreach but I do not know how to reference the boxes. Thanks in advance for any help.

#chatbox{
    border:2px solid #0969A2;
    height:250px;
    width:200px;
    background-color:#fff;
position:fixed;
z-index:11002;
padding:3px;
}

    $('#open-chat').live('click', function() {
    var user=$(this).attr('data-name');
    //check if bar exists
    if ($("#bar-icon[data-name="+user+"]").length == 0){
        $('.dockleft-block').append('<div id="bar-icon" data-name="'+user+'">'+user+'</div>');
        $('body').append('<div id="chatbox" data-name="'+user+'"></div>');

        //position new boxes           
        $("#chatbox[data-name="+user+"]").css('bottom', '37px');

        var chatBoxeslength = $("div[id=chatbox]").length-1;

        if (chatBoxeslength == 0) {
            $("#chatbox[data-name="+user+"]").css('left', '35px');
        } else {
            width = (chatBoxeslength)*(225+7)+20;
            $("#chatbox[data-name="+user+"]").css('left', width+'px');
            $("#bar-icon[data-name="+user+"]").css('left', width-35+'px');
        }

    }
    //end if length
    });                                       
    //end click function


    $('.closechatbox').live('click', function() {
    user=$(this).attr('data-name');     
    $("#chatbox[data-name="+user+"]").remove();
    $("#bar-icon[data-name="+user+"]").remove();
//need to rearrange other boxes
    });

UPDATE

this was the solution on another chat script but I do not understand it
anantgarg.com/chat/sampleb.php
how do they reference each box as #chatbox_”+chatboxtitle successfully?

function restructureChatBoxes() {
    align = 0;
    for (x in chatBoxes) {
        chatboxtitle = chatBoxes[x];

        if ($("#chatbox_"+chatboxtitle).css('display') != 'none') {
            if (align == 0) {
                $("#chatbox_"+chatboxtitle).css('right', '20px');
            } else {
                width = (align)*(225+7)+20;
                $("#chatbox_"+chatboxtitle).css('right', width+'px');
            }
            align++;
        }
    }
}
  • 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-18T00:58:43+00:00Added an answer on May 18, 2026 at 12:58 am

    Why don’t you just have a reference to an array of the chat-window divs. Then as you add and remove them, adjust the array. After you adjust the array, you should just reposition everything in the array.

    Something along these lines:

    var chatWindows = [];
    var windowWidth = 100;
    var padding = 10;
    
    function newChatWindow(divElement)
    {
       chatWindows.push(divElement);
       reposition();
    }
    
    function reposition()
    {
       var el = null;
       for (var i = 0; i < chatWindows.length; i++)
       {
          el = chatWindows[i];
          el.style.bottom = 10
          el.style.right = windowWidth * i + padding;
       }
    }
    
    function removeChatWindow(index)
    {
       var el = chatWindows[index];
       el.parentNode.removeChild(el);
       var newArr = [];
       for (var i = 0; i < chatWindows.length - 1; i++)
       {
          if (i != index)
          {
              newArr.push(chatWindows[i]);
          }
       }
       chatWindows = newArr;
       reposition();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of elements (divs) and they represent items. I can delete
I have a large image, and a bunch of divs that I'm using as
I have a bunch of divs on my page that are added at run
I have a bunch of divs that I am expanding/retracting individually using .toggle and
I have a bunch of hidden images on my website. Their container DIVs have
I have a bunch of divs which I nest arbitrarily: <div> <div> <div>Apple</div> <div>
I want to toggle a bunch of divs that each have the same id.
I have a bunch of divs sprinkled throughout a long article. Each one, when
I have a parent div, and it houses a bunch of child divs. One
We have an HTML page which displays a bunch of pretty bars using divs

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.