Having trouble getting this JavaScript query to function properly

The initial div in the code snippet below showcases the name of a university. When this name is clicked, it activates the function display_people(). This function is responsible for displaying or hiding the individuals associated with that university. The names of these individuals are within a div element with the id "college_people", which initially has its display property set to none.

Upon clicking on an individual's name, another function called display_chat_box() kicks in to show the chat-box corresponding to that particular person.

The issue arises when the person's name is hidden using the toggle() method from jQuery, causing the chat-box to disappear as well. This unintended behavior occurs due to the chat-box being reliant on the onclick event of the person's name. To address this, I would like the chat box to remain visible even if the person's name is hidden.

Is there a way to achieve this without losing the chat-box along with the disappearance of the person's name?

<div id='state_college_container' onclick='display_people()'>
  <span id='state_college_span'>
    University Name
  </span>
</div>

<div id='college_people' style='display:none'>
  <div id='college_people_container' onclick='display_chat_box()'>
    <span id='college_people_span'>
      Individual's Name
    </span>
  </div>
</div>

function display_people() {
    $("#college_people").toggle();
}
function display_chat_box() {
    $(".chat_box").show();
}

The chat-box content resides in a separate HTML file under the class name chat_box, functioning independently of other elements.

Below is the HTML structure for the chat box:

<div class="chat_box">
    <div id="chat_box_bar">
    <span id="chat_with">Your name</span>
    <span id="close_chat" onclick="close_chat_box()">X</span>
    </div>
    <div id="previous_chat1" >
       <span> Hi, how are you?</span>         
    </div>
     <div id="textarea_container">
    <textarea onkeypress="return detectEnter(event)" id="chat_content1"  name="posted_content1"></textarea>    
    </div>
</div>

Answer №1

I managed to make it function properly. It turns out that the issue stemmed from where the chat-box code was located (it was in the wrong file).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using ASP.NET MVC to generate dynamic CSS styles

I am seeking a solution that will allow me to achieve the following objectives: Retrieve dynamically generated CSS from an action method Select a CSS file based on request parameters or cookies Utilize a tool for combining and compressing (minifying) CS ...

Retrieve updated information from a specific row in the DataTable

I'm having trouble printing the correct content from a row in my data table. In my file named response.php, the following content is present: //include connection file session_start(); include_once("connection.php"); // initialize all variables $pa ...

Invoke a Java script function for Regular Expression validation failure in ASP.NET

I have a <asp:RegularExpressionValidator> that validates a text box, and I also have a JavaScript function that prevents entering non-numerical values in the textbox. When I use the expression validator alone, it works fine. However, as soon as I add ...

Tips for utilizing setState to display specific information fetched from an API call through the mapping method

Is there a way to utilize setState in order to render individual data retrieved from an API call? Despite my efforts, all I seem to get is another array of data. Here's the code snippet: const [likes, setLikes] = useState(0); useEffect( async () = ...

Error 422 encountered while trying to create a new asset using the Contentful Content Management API

My attempt to create and publish an image as an asset using the Contentful Content Management API has hit a roadblock. I managed to successfully create and publish an entry, but I can't seem to figure out why creating an asset is not working as expect ...

The node sends a request to the API to retrieve data, which is then stored in an array. Subsequently, another request is

var UfcAPI = require('ufc-api'); var ufc = new UfcAPI({ version: '3' }); const fighterIdList = []; function fetchFighterIds() { ufc.fighters(function(err, res) { for (let i = 0; i < res.body.length; i++) { ...

eliminate item from list upon user clicking the button

Does anyone have any tips on how to effectively store and remove user-selected items from an object in JavaScript? I'm encountering an issue where only the first object in the array is being removed, and not the others. Any help would be appreciated! ...

Transform the JSON data using jQuery into a specific structure

My current project involves creating a pie chart using flot, and I am receiving JSON data from the server in the following format: [ {"transactions": 7, "products__name": "mark"}, {"transactions": 12, "products__name": "vicky"}, {"transactions": 3 ...

angular does not update dynamically created dropdowns with populated arrays

Upon loading the page, my initial dropdown functions correctly. However, the child dropdown is loaded from localstorage after the first dropdown. The issue arises when I load the second dropdown and set it to the default value - at this point, I am unabl ...

Retrieve the location of the selected element

We are faced with the challenge of determining the position of the button clicked in Angular. Do you think this is achievable? Our current setup involves an ng-grid, where each row contains a button in column 1. When the button is clicked, we aim to displ ...

Customizing Material UI Stepper styles using CSS API

I am trying to customize the text color (represented by an SVG Icon) in Material UI StepIcon for active and completed steps only. Currently, I have successfully changed the icon color for those steps. This is how my custom MuiTheme appears: export default ...

Geometry is making its debut appearance in ThreeJS for the very first time!

Currently, I am experimenting with a simple script using ThreeJS to create a point wherever you click on the screen. Below is the function responsible for adding the point: function addPoint(coord){ var geometry = new THREE.BufferGeometry(); var verti ...

I am looking to deactivate the Log-in time button

I am looking to implement a functionality where the Login time button is disabled, but when the Logout time button is clicked, I want to enable the login button again. However, if the page is refreshed and the user has already printed their login time, I d ...

Tips for controlling or concealing slot elements within child components in Vue Js

I'm working with a named slot: <div name="checkAnswer" class="w-[70%] mx-[15%] flex items-center justify-center" > <button class="p-3 rounded-3xl shadow-md font-bold m-4 px-10 border-2 bo ...

Send the form to the webpage and display various div elements based on the entered information

I have created a form that is designed to display one of four hidden divs on a page, depending on the input provided. Here is the form: <form> <input id="place" name="place" type="text"> <input name="datepicker" type="text" id="datepicker" ...

Vue 2.0 custom filter not producing any output

I am attempting to create a customized filter that identifies and returns the items that correspond to a given input. It functions effectively with basic arrays like ['Apple', 'Banana', 'Cupple'], but encounters difficulty whe ...

The dropdown function in Bootstrap seems to be malfunctioning

I have implemented a basic dropdown menu using the code below: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" ...

Function Errors, How to Fix Them?

I've recently developed a tool for character creation within a new video game. However, I'm currently facing an issue: When it comes to assigning points in Magic Power or Weapon Power for the Warrior and Wizard characters, there seems to be a p ...

The positioning of the Kendo UI window is off-center

I have encountered a problem with the alignment of the Kendo Window. There is a simple fiddle available to demonstrate this issue. Despite having ample space for the Kendo window to show without triggering the browser's vertical scroll bar, the cente ...

The distance calculation is not functioning properly within the for loop

I am currently working on developing a geolocation test app. After finding some useful code for calculating the distance between two points using latitude and longitude coordinates, I am attempting to create a loop using a for loop to calculate the distan ...