Skip to main content

div Toggle using JS not working as expected

I have written the following code and am facing issues with getting the JS to work as expected.

function online() {
  var online = document.getElementById("online");
  var requests = document.getElementById("requests");
  var blocks = document.getElementById("blocks");

  if (online.style.display === "none") {
    online.style.display = "block";
    requests.style.display = "none";
    blocks.style.display = "none";
  } else {
    online.style.display = "block";
    requests.style.display = "none";
    blocks.style.display = "none";
  }
}


function requests() {
  var online = document.getElementById("online");
  var requests = document.getElementById("requests");
  var blocks = document.getElementById("blocks");

  if (requests.style.display === "none") {
    online.style.display = "none";
    requests.style.display = "block";
    blocks.style.display = "none";
  } else {
    online.style.display = "none";
    requests.style.display = "block";
    blocks.style.display = "none";
  }
}

function blocks() {
  var online = document.getElementById("online");
  var requests = document.getElementById("requests");
  var blocks = document.getElementById("blocks");

  if (blocks.style.display === "none") {
    online.style.display = "none";
    requests.style.display = "none";
    blocks.style.display = "block";
  } else {
    online.style.display = "none";
    requests.style.display = "none";
    blocks.style.display = "block";
  }
}
.friend-list-window {
  border: 3px solid rgb(0, 0, 0);
  background-color: rgb(160, 156, 156);
  color: #fff;
  border-collapse: collapse;
  border-radius: 5px;
  text-align: center;
  list-style-type: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.friend-list-header {
  background: #000;
  padding: 4px 0;
  display: block;
}

.friend-list-header h4 {
  display: inline-block;
  width: 90%;
}

.friend-list-details button {
  width: 30%;
  margin: 5px 0;
  padding-top: 2px;
  border-bottom: none;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  display: inline-block;
  border: none;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: background 250ms ease-in-out, transform 150ms ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: rgb(182, 175, 175);
}

.friend-list-window input {
  width: 90%;
  border-radius: 5px;
  margin: 5px;
  padding: 2px;
  height: 15px;
}

.online-users,
.new-requests,
.block-list {
  display: inline-block;
  width: 90%;
}

.user-available,
.user-request,
.user-block {
  display: inline-block;
  width: 100%;
}

.user-available ul,
.user-request ul,
.user-block ul {
  float: left;
  font-size: small;
  display: inline-block;
  font-weight: bold;
  color: black;
}

.user-available button,
.user-request button,
.user-block button {
  width: 50px;
  float: right;
  margin-left: 5px;
  border-radius: 5px;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: background 250ms ease-in-out, transform 150ms ease;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.friend-list-details button:hover {
  background-color: greenyellow;
}

.friend-list-details button {
  background: ivory;
}

.remove-friend,
.reject-request {
  border: 1px solid white;
  background-color: red;
  color: white;
  font-weight: bold;
  font-size: x-small;
}

.message-friend,
.accept-request,
.unblock-user {
  border: 1px solid white;
  background-color: green;
  color: white;
  font-weight: bold;
  font-size: x-small;
}
<div class="friend-list-window" id="frndlist">
  <div class="friend-list-header">
    <h4>Friend List</h4>
  </div>
  <div class="friend-list-details">
    <button type="button" onclick="online()"><i class="fas fa-users"></i> Online</button>
    <button type="button" onclick="requests()"><i class="fas fa-user-plus"></i> Requests</button>
    <button type="button" onclick="blocks()"><i class="fas fa-users-slash"></i> Block List</button>
  </div>
  <input type="text" placeholder="Search">
  <div class="online-users" id="online">
    <div class="user-available">
      <ul>Groot</ul>
      <button class="remove-friend">Unfriend</button>
      <button class="message-friend">Chat</button>
    </div>
    <div class="user-available">
      <ul>Groot</ul>
      <button class="remove-friend">Unfriend</button>
      <button class="message-friend">Chat</button>
    </div>
    <div class="user-available">
      <ul>Groot</ul>
      <button class="remove-friend">Unfriend</button>
      <button class="message-friend">Chat</button>
    </div>
  </div>
  <div class="new-requests" id="requests">
    <div class="user-request">
      <ul>Groot</ul>
      <button class="reject-request">Reject</button>
      <button class="accept-request">Accept</button>
    </div>
    <div class="user-request">
      <ul>Groot</ul>
      <button class="reject-request">Reject</button>
      <button class="accept-request">Accept</button>
    </div>
    <div class="user-request">
      <ul>Groot</ul>
      <button class="reject-request">Reject</button>
      <button class="accept-request">Accept</button>
    </div>
  </div>

  <div class="block-list">
    <div class="blocked-user" id="blocks">
      <div class="user-block">
        <ul>Groot</ul>
        <button class="unblock-user">Unblock</button>
      </div>
      <div class="user-block">
        <ul>Groot</ul>
        <button class="unblock-user">Unblock</button>
      </div>
      <div class="user-block">
        <ul>Groot</ul>
        <button class="unblock-user">Unblock</button>
      </div>
    </div>
  </div>
</div>

When the website loads this is how it is displayed Initial View


When I click on any of the buttons, say Requests or Block List, this is how it is displayed On clicking Requests or Block List


When I click on Online again, this is how it is displayed On clicking Online again

So, as you can see, I'm not sure what I'm doing wrong here and what is causing the data to not display when I click on Requests or Block List and what is causing the formatting issue when I click Online again.

Thanks in advance

Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

Comments

Popular posts from this blog

Prop `className` did not match in next js app

I have written a sample code ( Github Link here ). this is a simple next js app, but giving me error when I refresh the page. This seems to be the common problem and I tried the fix provided in the internet but does not seem to fix my issue. The error is Warning: Prop className did not match. Server: "MuiBox-root MuiBox-root-1" Client: "MuiBox-root MuiBox-root-2". Did changes for _document.js, modified _app.js as mentioned in official website and solutions in stackoverflow. but nothing seems to work. Could someone take a look and help me whats wrong with the code? Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console