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
When I click on any of the buttons, say Requests or Block List, this is how it is displayed
When I click on Online again, this is how it is displayed
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
Post a Comment