It is not possible to make the event click work on the contents within a div

After conducting a sample chat, I am puzzled by the fact that the links or interactive buttons are not working within the content of the div.

var ChatCompMap = new Map();

function ChatComponent(c, ident, userimg, username) {

  let id = c + '_' + ident;

  if (!ChatCompMap.has(id))
    ChatCompMap.set(id, {
      chat: c,
      user: ident
    });
  else
    return;

  let chatdiv = document.getElementById(c);

  if (!chatdiv.classList.contains("chat")) {
    /* Required Components */
    var el = document.createElement('style');
    el.innerHTML = '';
    document.head.appendChild(el);

    el = document.createElement('link');
    el.setAttribute("rel", "stylesheet");
    el.setAttribute("crossorigin", "anonymous");
    el.setAttribute("href", "https://cdn.jsdelivr.net/gh/englishextra/img-lightbox@latest/img-lightbox.min.css");
    document.head.appendChild(el);

    el = document.createElement('script');
    el.setAttribute("src", "https://cdn.jsdelivr.net/gh/englishextra/img-lightbox@latest/img-lightbox.min.js");
    el.onload = function(e) {
      imgLightbox("img-lightbox-link");
    }
    document.head.appendChild(el);

    chatdiv.classList.add("chat");

  }

  let nchatcontainer = document.createElement("div");
  nchatcontainer.setAttribute("id", ident);
  nchatcontainer.setAttribute("class", "chat-container");

  let nchatuserbar = document.createElement("div");
  nchatuserbar.setAttribute("class", "user-bar");

  let nchatconv = document.createElement("div");
  nchatconv.setAttribute("class", "conversation");

  let nchatconvcont = document.createElement("div");
  nchatconvcont.setAttribute("class", "conversation-container");

  let nchatavatar = document.createElement("div");
  nchatavatar.setAttribute("class", "avatar");

  let nchatname = document.createElement("div");
  nchatname.setAttribute("class", "name");

  nchatconv.append(nchatconvcont);

  nchatuserbar.append(nchatavatar);
  nchatuserbar.append(nchatname);

  nchatcontainer.append(nchatuserbar);
  nchatcontainer.append(nchatconv);

  chatdiv.append(nchatcontainer);

  let url = null;

  if (!userimg)
    userimg = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==";

  url = userimg;

  if (!username)
    username = "User #" + ChatCompMap.size.toString();

  let img = document.createElement("img");
  img.src = url;

  let slct = '#' + c + ' > #' + ident + ' > div.user-bar > div.avatar';
  let slctn = '#' + c + ' > #' + ident + ' > div.user-bar > div.name';

  let obj = document.querySelector(slct);
  obj.append(img);

  obj = document.querySelector(slctn);
  obj.innerHTML = username;

}

// The rest of the Javascript functions remain the same

// The CSS styling also remains unchanged 

// The HTML structure and content is identical

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Chat</title>
</head>

<body>
  <script>
    var avatar = "http://sistemas.corcino.com.br:8020/somos/getfile.rule?sys=BOT&arquivo=userimage@1@4@7FD66E9B1F9F486D8C95";
    var nphoto = "http://sistemas.corcino.com.br:8020/somos/getfile.rule?sys=BOT&arquivo=dataimage_jpeg@1@4@C661281C60B847759EEB";
    var nvideo = "http://sistemas.corcino.com.br:8020/somos/getfile.rule?sys=BOT&arquivo=datavideo_mp4@1@4@4F5D6E742634422DAF2B";
    var nlocation = "location@1@4@314123992DA4406CAA7F";
    var ndocument = "http://sistemas.corcino.com.br:8020/somos/getfile.rule?sys=BOT&arquivo=04contrachequeintranetperbras_pdf@1@4@7168A9C3138745E99F3C";
    var naudio = "http://sistemas.corcino.com.br:8020/somos/getfile.rule?sys=BOT&arquivo=dataaudio_ogg@1@4@16CC8FAD9C8A469A8125";
    var latlon = "-10.9498287,-37.0654272";
  </script>


  <div id="chat"></div>

</body>

</html>

Answer №1

Make sure to check your stylesheet rules for any z-index conflicts. Elements with a lower z-index, like -1, may prevent divs from being clickable if there are higher z-index elements present. Also, double-check your onclick handlers in the markup for typos; they should be written as "onclick" and not "nclick."

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Chat</title>

    /* Make sure to review and adjust CSS styles below */

  </head>

  <body>
    <script>
      // JavaScript functions and components
    </script>
  </body>
</html>

Best regards!

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

The request body contains no information

I'm having trouble debugging this issue. Can anyone help me out? When using console.log(req.body), I am getting an empty object {}. I've tried multiple approaches but still can't figure out the problem. Even after attempting to use middle ...

Google/StackExchange Menu Tab

I am interested in creating a navigation bar similar to Google's or StackExchange's new one, where it is always positioned at the top. It does not need to be fixed there, but I would like it to have links only. How can I achieve this layout with ...

Transforming a JSON into a JavaScript object using deserialization

Within a Java server application, there exists a string that can be accessed through AJAX. The structure of this string is exemplified below: var json = [{ "adjacencies": [ { "nodeTo": "graphnode2", "nodeFrom": "graphnode1" ...

Showing options in the navigation bar upon user authentication with Passport in NodeJS

When a user is connected, I want the navbar to display "Profile of: {USER}", otherwise it should show a set of Sign up/Login tabs. The challenge lies in using EJS with separate "head.ejs" and "header.ejs" sections placed in a /partials folder within the / ...

Conceal the complete <div> in the event that the <table> contains no data

My task involves managing a div containing a table. The goal is to hide the div if it has no value or is empty, and then show it again once it has a value. <div class="container" id="main_container"> <table id="my_tabl ...

Providing parameters to a helper function in one class which invokes a method in another class

I have a prototype method that looks like this: ProjectClient.prototype = { connect: function() { console.log('ARGS: ' + Array.prototype.slice.call(arguments) // This part takes a data object, a relationship string, and anoth ...

Validating forms using jQuery before making an Ajax call to submit them

I'm struggling to implement form validation before submitting it via Ajax to my php script. Despite researching on stackoverflow, I haven't found a solution that fits my needs. My form consists of 3 inputs and a submit button: <input type="t ...

What is the best way to align the action buttons on this webpage?

I'm struggling to center both buttons on the page. I've tried using margin:0 auto 0 auto; in the position property, but it doesn't seem to work. Strangely, when I used a table instead of a div, it worked. I'm curious to know why I can&a ...

Requirements for two buttons

One of the requirements I have is that if the user chooses Radio button A, then a specific button should be displayed. <input type="button" disabled="disabled" name="next" value="Proceed to Payment" onclick="window.location='shipping.php#openModal ...

What is the process of transferring information from a form to mongodb?

I have created a nodejs project with the following structure: https://i.stack.imgur.com/JiMmd.png api.js contains: const express = require('express'); const router = express.Router(); const add = require('../model/myModel'); router.g ...

Global variables in AngularJS that are asynchronous

My challenge lies in using AngularJS to create several global objects accessible by any controller within the application. One crucial object I require is a user object containing the user's ID and other essential properties retrieved from the databa ...

What is the best way to query based on a nested object property in Mongoose?

const collection = [ { inner_obj: { prop: "A" } } ] Get the outer records by searching for the ones that match the value of the `prop` property within the `inner_obj` column. How can we locate the o ...

"Unleash the power of the Web Audio API by releasing

Currently, I am utilizing the WEB Audio API within a Webapp to render an Audio Signal. However, I have encountered an issue where Chrome's RAM usage gradually increases as it loads an audio file every second. Unfortunately, I am unsure of how to relea ...

Adding a character to an AngularJS textbox

I am attempting to add the "|" Pipe symbol to a textbox when a button is clicked, using this function. $scope.appendPipe = function(){ var $textBox = $( '#synonyms' ); $textBox.val($textBox.val()+'|'); //textBox ...

How can I retrieve the "src" value of an iframe using PHP?

I have a webpage containing an iframe, where upon clicking a menu item, the iframe's URL is updated based on the selection. This functionality is achieved by invoking a JavaScript function on 'onclick', which passes the selected URL from th ...

Disabling the Enter key to submit an AJAX form is causing the focus to not move to the next input field

I've encountered a small issue that I can't seem to find a solution for (maybe my keyword search wasn't effective): The scenario: I have successfully prevented a form from being submitted when hitting the Enter key (13). It's importan ...

Experiencing difficulties when trying to pan and zoom the data obtained from d3.json within a line chart

I am currently working on developing a trend component that can zoom and pan into data fetched using d3.json. Here is the code I have written so far: <script> var margin = { top: 20, right: 80, bottom: 20, left: 50 }, width = $("#trendc ...

Twofold Arrow Styling in CSS

Can someone help me achieve this design: https://i.stack.imgur.com/eBQ1a.png I am attempting to create a double arrow using just one class. I have tried various methods, but nothing seems to be working for me. If anyone has any suggestions or can point ...

Having trouble dynamically displaying the '<' symbol using JavaScript?

Whenever I attempt to show a string with the character '<' in it, the part of the string that comes after the symbol is not displayed. Strangely enough, when I output it to the console, it appears correctly. Take a look at this excerpt showcas ...

Cannot assign argument of type 'string | undefined' to parameter expecting type 'string'. Typescript is being strict

While attempting to update an object using the SDK and having 'strict' mode enabled in typescript, I encountered the following error: const offer = client.offer(oldOfferDefinition!.id); await offer.replace(newOfferDefinition); error TS2345: Argu ...