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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:47:25+00:00 2026-05-29T11:47:25+00:00

UPDATE : A commenter told me to change some codes, this is the new

  • 0

UPDATE: A commenter told me to change some codes, this is the new code and its not working neither.

I’m creating a Facebook-Like chat. It gets the latest messages “Not Read” from a JSON file and it appends the text to an “UL” element vía “LI” into a box. If the box doesn’t exist, it creates and attach the text. I want that when I click that div, it hides using margin-bottom negative, and when I click it again it shows by Margin-Bottom:0. Please help me since it’s just not working.

function showChat(id){
$(this).animate({marginBottom : "0"}).removeClass("hidden_box").addClass("active_box").removeAttr('onclick').click(function(){
       hideChat(Id);
    });

}
function hideChat(id){
$(this).animate({marginBottom : "-270px"}).removeClass("active_box").addClass("hidden_box").click(function(){
       showChat(Id);
    });

}

function getOnJSON(){

//Creating Variables that will be used
var from;var to;var msg_id;var msg_txt;

//Getting the data from the json file
$.getJSON("/ajax/chat.json.php",function(data){

//Repeat for each result
$.each(data.notif, function(i,data){

//Getting a var to info
from = data.from;to = data.to;msg_id = data.id;msg_txt = data.text;

//check if div exists
        if ($("#chat_"+from+"_lp").length === 0){

//If not, create the div
            $("#boxes").append('<div id="chat_'+from+'_lp" class="chat_box hidden_box clickable_box"></div>');

//Add the senders name
            $("#chat_"+from+"_lp").append('<div id="'chat_+from+'_nick" class="chat_name">'+from+'</div>');

//Add the chats UL
            $("#chat_"+from+"_lp").append('<ul id="chat_'+from+'_txt" class="chat_txt"></ul>');

//Add the message text
            $("#chat_"+from+"_lp").append('<li id="' + msg_id + '">'+ msg_txt+'</li>');

//Add event handler for each div
            $('#chat_'+from+'_lp').click(function() {showChat(this);});

//If div exists just add the text
        }else{

//Add the message text
            $("#chat_"+from+"_txt").append('<li id="' + msg_id + '">'+ msg_txt+'</li>');

//Add event handler for each document
            $('#chat_'+from+'_lp').click(function() {showChat(this);});

//Close If
        }
//Close data for each item      
    });

//Close JSON
});

//Close Function
}

UPDATE 2: in order to stop making and appending things, I made an unique HTML string that is going to be appended.

new_chat_string = '<div id="chat_'+from+'_lp" class="chat_box hidden_box clickable_box"><div id="'chat_+from+'_nick" class="chat_name">'+from+'</div><ul id="chat_'+from+'_txt" class="chat_txt"><li id="' + msg_id + '">'+ msg_txt+'</li></ul></div>';

$("#boxes").append(new_chat_string);    
  • 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-29T11:47:26+00:00Added an answer on May 29, 2026 at 11:47 am

    use class instead of id

    <div id="chat_sender_lp" class="chat_box hidden_box clickable_box sender-click"
    

    then

    $('.hidden_box.sender-click').live('click', function(){
       $(this).slideToggle(500);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Solved, with code I got it working, see my answer below for the
I'm trying to update the comments column in one table (Entries), when a new
The same as this question but for java Update Based on the comments and
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update : Looks like the query does not throw any timeout. The connection is
QUESTION 1 I have to update some fields of a table of access according
I have a problem with this piece of code If I don't use the
I'm rewriting an old program to do some new stuff, and suddenly I get
UPDATE (5 July 2013): I've learned much since I originally asked this question. In
Update : I have a couple of what are probably silly questions about commenter

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.