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

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...