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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:41:23+00:00 2026-06-16T03:41:23+00:00

I have a variable mutedUser which I would like to have persist to another

  • 0

I have a variable mutedUser which I would like to have persist to another function. I am having a bit of trouble with the variable persisting outside the click event. What would be the best way to have it so the “return mutedUser” would keep the “muted” string addition based on the conditions of the if statement being met? Thanks!

*The console.log’s were me checking to see where the persistance stops

this.isUserMuted = function isUserMuted(payload) {
  var mutedUser = '';
  // If mute button is clicked place them into muted users list
  // check for duplicates in list
  $("#messages-wrapper").off('click', '.message button.muteButton');
  $("#messages-wrapper").on('click', '.message button.muteButton', function(e) {

      $('#unMute').show();

      //create userId reference variable
      var chatUserID = parseInt($(this).parent().parent().attr("data-type"));

      //store userId in muted user object
      mutedUsers[chatUserID] = {};
      mutedUsers[chatUserID].id = chatUserID;
      mutedUsers[chatUserID].muted = true;

      if (mutedUsers[chatUserID] !== null && mutedUsers[chatUserID].id === payload.a) {
          console.log("user is now muted");
          mutedUser += ' muted';
          console.log(mutedUser + 1);
      }
      console.log(mutedUser + 2);
  });
  return mutedUser;
};
  • 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-16T03:41:24+00:00Added an answer on June 16, 2026 at 3:41 am

    If I understood what you’re trying to do (by looking at the code), this would be the best approach:

    // If mute button is clicked place them into muted users list
    // check for duplicates in list
    $("#messages-wrapper").off('click', '.message button.muteButton');
    $("#messages-wrapper").on('click', '.message button.muteButton', function(e) {
        $('#unMute').show();
    
        //create userId reference variable
        var chatUserID = parseInt($(this).parent().parent().attr("data-type"));
    
        //store userId in muted user object
        mutedUsers[chatUserID] = {};
        mutedUsers[chatUserID].id = chatUserID;
        mutedUsers[chatUserID].muted = true;
    });
    
    this.isUserMuted = function isUserMuted(payload) {
      var mutedUser = '';
    
      if (mutedUsers[payload.a] !== null) {
          mutedUser += ' muted';
      }
    
      return mutedUser;
    };
    

    The code retains the array of mutedUsers, and isUserMuted function checks if provided user is in that array. In the code you provided, you would attach a new event handler every time isUserMuted function is called..

    The isUserMuted function could even be shortened to:

    this.isUserMuted = function isUserMuted(payload) {
      return mutedUsers[payload.a] !== null ? ' muted' : '';
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have variable which I populate from JSON formated data. Something like: var time=my_data[data.results[i].id].time;
I'd like to have variable defined in the nesting function to be altered in
I have variable call items having array of items which contains following value [[#<Item
I have several buttons that have variable width and I would like them to
i have variable $lang which convert string to the selected language but i am
How I can have variable number of parameters in my function in C++. Analog
I have variable like float num = (x/y); I need to round up the
Is it possible a lambda function to have variable number of arguments? For example,
So let's say I have variable like this one: $q = DB::select('id')->from('reports')->where('field', '=', 'value');;
I often work with text files which have a variable amount of whitespaces as

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.