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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:06:23+00:00 2026-06-06T07:06:23+00:00

Alright, so I’m making a Facebook-style chat. But that doesn’t really matter. See here:

  • 0

Alright, so I’m making a Facebook-style chat. But that doesn’t really matter.

See here:
http://jsfiddle.net/SkHme/7/

Nice and pretty, right? Well, there’s a problem. Notice this line:

<div class="conversation EmperorCuzco" onclick="setActive('EmperorCuzco')">

See the onclick attribute? Well, it’s not working. However, I have confirmed that the function itself DOES work. (if you run it just like that in the JavaScript, it runs like a dream) I have further confirmed that the function is not the problem by attempting to replace the onclick value with a simple alert('blah'), but that doesn’t work either.

So, what’s up? I’m guessing that something in my JavaScript is somehow disabling something, but I have absolutely no idea what it could be, nor how I could go about fixing it. I did some web searching, but couldn’t find anything that helps.

What’s going on?

  • 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-06T07:06:25+00:00Added an answer on June 6, 2026 at 7:06 am

    Your setActive function is defined inside the scope of the $(document).ready handler. Move the function outside that function so that it is in the global scope.

    Right now it looks like this:

    $(document).ready(function()
    {
        // ...
        function setActive(new_conversation)
        {
            // ...
        }
    });
    

    Now change that to:

    $(document).ready(function()
    {
        // ...
    });
    
    function setActive(new_conversation)
    {
        // ...
    }
    

    Really though, you should separate your content from your interactions and bind those event handlers in your script itself. Something like:

    // Refers to the last clicked conversation *button*
    // Initialize to empty jQuery object
    var $active_conversation = $([]);
    
    // Binding on #chat, targeting click events on .conversation_button children
    $("#chat").on("click", ".conversation_button", function() {
        // Hide currently active conversation
        $active_conversation.hide();
        $active_conversation.siblings('.conversation_button').removeClass("selected");
    
        // Set as currently active conversation button
        // Note: this refers to the clicked <div class="conversation_button">
        var $this = $(this);
        $active_conversation = $this.siblings('.conversation');
    
        // Show this conversation
        $active_conversation.show();
        $this.removeClass("alert").addClass("selected");
    });
    

    Some advantages of this approach:

    • You don’t need different classes for different conversations. By storing the actual conversation DOM element (as a jQuery object) in $active_conversation, the conversation can be identified without any extra processing.
    • You can add and remove whole list items with a conversation without assigning new event handlers. In the sample above, the event handler for all .conversation_button elements is defined at the level of #chat. For more about this binding mechanism, read up on .on (or .delegate for pre-1.7).

    Here, have an updated fiddle! 🙂

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

Sidebar

Related Questions

Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright, here we go! I am currently developing an iPhone app that will work
Alright, so I'm about 90% sure that this isn't possible, but I thought I'd
Alright so i need to open a .txt file that will be created in
Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have no idea how to even begin doing this But basically
Alright so I have been looking around (on SO and Google) to see if
Alright, here I am again trying to write code from scratch and I can't
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright y'all. I am attempting to write a bit of code that places typographic

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.