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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:38:25+00:00 2026-05-26T05:38:25+00:00

hey guys last final piece to my jquery/javascript chat box stopped working if i

  • 0

hey guys last final piece to my jquery/javascript chat box stopped working if i clone my chat
with javascript.

This is my javascript code to clone and change the id of a few divs.

e.g it changes the ch, chat and chatbox ids/classes.

by one for instance

<div class="chat" id="chat">
<div id="ch" class="ch">
               <h2>Chat</h2></div>
               <div class="chatbox" id="chatbox">
               <div class="messages"></div>
               <textarea id="message" class="chatinp" 
               rows="3" cols="27"></textarea>
               <button class="send">Send</button></div>
</div>

and everytime it clones it changes the id of chat,ch and chatbox but keeping the original the same

like so…

clone1

    <div class="chat" id="chat1">
    <div id="ch1" class="ch">
                   <h2>Chat</h2></div>
                   <div class="chatbox" id="chatbox1">
                   <div class="messages"></div>
                   <textarea id="message" class="chatinp" 
                   rows="3" cols="27"></textarea>
                   <button class="send">Send</button></div>

</div>

Clone2

<div class="chat" id="chat2">
<div id="ch2" class="ch">
               <h2>Chat</h2></div>
               <div class="chatbox" id="chatbox2">
               <div class="messages"></div>
               <textarea id="message" class="chatinp" 
               rows="3" cols="27"></textarea>
               <button class="send">Send</button></div>
</div>

var num = new Number();
num = 0



function chat(){
if(!document.getElementById("chat")){
var chatdiv = document.createElement('div');
  chatdiv.id = 'chat';
  chatdiv.className = 'chat';
  chatdiv.innerHTML = 
              ['<div id="ch" class="ch">',
               '<h2>Chat</h2></div>',
               '<div class="chatbox" id="chatbox">',
               '<div class="messages"></div>',
               '<textarea id="message" class="chatinp" ',
               'rows="3" cols="27"></textarea>',
               '<button class="send">Send</button></div>'
              ].join(' ')
  document.body.appendChild(chatdiv); 

} 
else 
{
var obj  = document.getElementById("chat").cloneNode(true),
      children = obj.childNodes;
  num += 1;
//change the id of the cloned element
  obj.id = obj.id+num;

  //traverse the child nodes of obj to
  //change id (call function changeId)
  if (num<16){
      changeId(children,num);
  }

  //now appending obj to the document.body should be sufficient
var p = $(".chat");
var offset = p.offset();
var left = offset.left + 261;
//now appending obj to the document.body should be sufficient
document.body.appendChild(obj);
document.getElementById("chat").style.left = left + "px";

  //demonstrate that the id value has changed
  var nwchatbox = document.getElementById('chatbox'+num)
  nwchatbox.value = 'my id = '+nwchatbox.id;

  //function to add number to id's of a nodelist (recursive)
  //used in the above 
  function changeId(nodes, n){
   for (var i=0;i<nodes.length;i=i+1){
     if (nodes[i].childNodes){
           changeId(nodes[i].childNodes,n);
     }
     //if id value is 'ch' or 'chatbox', change it
     if(nodes[i].id && /^ch$|^chatbox$/i.test(nodes[i].id)) {
      nodes[i].id += String(n);
     }
   }
  }
}
}

ok my question is how do i slideToggle a chat box individuality
and every time i clone a chat box it changes the adds a instance to the jquery so it will open up the clone?

ok you open the chat box by pressing on the “ch” id/class and it pushes the chatbox class/id up. but remember everytime i clone it, it changes the id of the “ch” div

thanks for your help

  • 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-26T05:38:25+00:00Added an answer on May 26, 2026 at 5:38 am

    Right after you clone the chatbox, you need to register another click handler:
    $('#ch'+num).click(clickHandler)

    You need to make the clickHandler generic. So the handler would look like:

    function clickHandler(e){
        var id = this.id.substring(2);
        //Now initiate sliding behavior
        $("#chatbox"+id).slideToggle(...);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I was wondering why my last script in this file isn't working
Hey Guys, here is my code for this, the only help i get from
hey guys, i manage to get this script working to pull data from my
Hey guys, I have a javascript function that produces a 12 digit UPC code
Hey guys, this bit of code works in IE but not in Chrome, any
Hey guys, I searched the last 4 hours to solve this issue, I wasn't
Hey guys, I want to store a categorized list of URLs. This is an
Hey you guys (and girls), I have implemented the following CSS: #tab-navigation ul li:last-child
Hey, guys, I tried to ask this yesterday but I didn't explain myself clearly
Hey guys, I always get confused by this so it's not exactly my strong

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.