javascript - Content in the second option of a pop up tab not showing anything
one text
I have a pop up tab where users can check their messages and another is their notification. Currently, when my code only has this:
<div class="inbox active" id="inbox">
<form action="includes/chatsearch-inc.php" method="POST">
<input type="text" name="search" placeholder="Search a user or applicant\'s name">
<button name="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<div class="notifications" id="notifications">
<div class="notifications__container" onclick="location.href=\'job?jid='.$jobsid.'\'">
<img src="profilepic/'.$notifsusersprofilepic.'" alt="'.$notifsusersname.'\'s profile picture" class="profilepic">
<div class="notifications__info__container">
<p class="notifications__info"><b>'.$notifsusersname.'</b> applied to your job listing. </p>
<p class="notifications__info date">'.$notifsdate.'</p>
</div>
</div>
<hr class="notifications__divider">
</div>
And CSS is:
.tabs {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 75%;
height: 75%;
background: #fff;
padding:2em;
overflow:hidden;
box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
border-radius: var(--border-radius);
z-index: 102;
}
.tabs .tab-header {
height:3rem;
display:flex;
align-items: center;
}
.tabs #close_header_tabs {
display: flex;
justify-content: flex-end;
}
.tabs .tab-header > div {
width:calc(100% / 2);
text-align:center;
color:#888;
font-weight:600;
cursor:pointer;
font-size:.85em;
text-transform:uppercase;
outline:none;
transition: color 0.2s;
}
.tabs .tab-header > div > i {
display:block;
margin-bottom:5px;
}
.tabs .tab-header > div.active {
color:#00acee;
}
.tabs .tab-header > div.active > i {
display:block;
color: #8bc34a;
margin-bottom:.3rem;
}
.tabs .tab-indicator {
position:relative;
width:calc(100% / 2);
height:.3rem;
background:#00acee;
left:0px;
border-radius:var(--border-radius);
transition:all 500ms ease-in-out;
}
.tabs .tab-body {
position:relative;
height:calc(100% - 60px);
padding:.6em .3em;
}
.tabs .tab-body > div {
position:absolute;
top:-200%;
opacity:0;
transform:scale(0.9);
transition:opacity 500ms ease-in-out 0ms,
transform: 500ms ease-in-out 0ms;
}
.tabs .tab-body > div.active {
top:0px;
opacity:1;
transform:scale(1);
}
.tabs .tab-header > div:hover {
color:#00acee;
}
.tabs .tab-body .notifications , .tabs .tab-body .inbox {
margin: 1em 0 2em;
border: 1.5px solid #d4d4d4;
border-radius: var(--border-radius);
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
max-height: 90%;
overflow: scroll;
overflow-x: hidden;
}
.tabs .tab-body .inbox form {
height: 5rem;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
padding: 0;
}
.tabs .tab-body .inbox form input {
width: 75%;
padding: 0.75rem;
box-sizing: border-box;
border-radius: var(--border-radius);
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border: 1px solid #dddddd;
outline: none;
background: #eeeeee;
overflow: hidden;
transition: background 0.2s, border-color 0.2s;
}
.tabs .tab-body .inbox form input:focus {
border-color: var(--color-primary);
background: #ffffff;
}
.tabs .tab-body .inbox form button {
width: 3em;
padding: .6em;
background: #2196F3;
border-radius: var(--border-radius);
border-top-left-radius: 0;
border-bottom-left-radius: 0;
color: white;
font-size: 17px;
border: 1px solid var(--color-primary);
border-left: none;
cursor: pointer;
}
.tabs .tab-body .notifications .notifications__container , .tabs .tab-body .inbox .inbox__container {
margin: .5em;
padding: 1em;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: auto;
cursor: pointer;
}
.tabs .tab-body .notifications .none, .tabs .tab-body .inbox .none {
cursor: default;
}
.tabs .tab-body .notifications .notifications__container .profilepic , .tabs .tab-body .inbox .inbox__container .profilepic {
width: 3.5rem;
height: 3.5rem;
background-position: center;
border-radius: 50%;
}
.tabs .tab-body .notifications .notifications__container .notifications__info__container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.tabs .tab-body .notifications .notifications__container .notifications__info__container .notifications__info {
margin: 0 1em;
font: 500 1rem 'Quicksand', sans-serif;
}
.tabs .tab-body .notifications .notifications__container .notifications__info__container .date {
margin-top: .5em;
font-size: .8em;
color: grey;
}
.tabs .tab-body .notifications .notifications__divider , .tabs .tab-body .inbox .inbox__divider{
border: 1px solid #d4d4d4;
width: 99%;
}
And my JS is:
let tabHeader = document.getElementsByClassName("tab-header")[0];
let tabIndicator = document.getElementsByClassName("tab-indicator")[0];
let tabBody = document.getElementsByClassName("tab-body")[0];
let tabsPane = tabHeader.getElementsByTagName("div");
for(let i=0;i<tabsPane.length;i++){
tabsPane[i].addEventListener("click",function(){
tabHeader.getElementsByClassName("active")[0].classList.remove("active");
tabsPane[i].classList.add("active");
tabBody.getElementsByClassName("active")[0].classList.remove("active");
tabBody.getElementsByTagName("div")[i].classList.add("active");
tabIndicator.style.left = `calc(calc(100% / 2) * ${i})`;
});
}
var backtotopbutton = document.getElementById("topButton");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
backtotopbutton.style.display = "block";
} else {
backtotopbutton.style.display = "none";
}
}
document.addEventListener("DOMContentLoaded", () => {
const openMessages = document.getElementById("open_inbox");
const openNotifications = document.getElementById("open_notifications");
openMessages.addEventListener("click", function () {
tabHeader.getElementsByClassName("active")[0].classList.remove("active");
tabsPane[0].classList.add("active");
tabBody.getElementsByClassName("active")[0].classList.remove("active");
tabBody.getElementsByTagName("div")[0].classList.add("active");
tabIndicator.style.left = `calc(calc(100% / 2) * ${0})`;
});
openNotifications.addEventListener("click", function () {
tabHeader.getElementsByClassName("active")[0].classList.remove("active");
tabsPane[1].classList.add("active");
tabBody.getElementsByClassName("active")[0].classList.remove("active");
tabBody.getElementsByTagName("div")[1].classList.add("active");
tabIndicator.style.left = `calc(calc(100% / 2) * ${1})`;
});
});
$(document).ready(function(){
$('#topnav_button').click(function() {
$('.nav').toggle(200);
});
$('#open_inbox, #open_notifications').click(function() {
$('#navHeader').show(200);
});
$('#close_header_tabs').click(function() {
$('#navHeader').hide(200);
});
$('#topButton').click(function() {
$('body, html').animate({
scrollTop:0
},300);
});
});
Notifications div has a sql to project all notifs not included in this question to minimize code. It shows both the content of messages and notifications tab.
But when I added another line of div inside my messages tab: example:
<div class="inbox active" id="inbox">
<form action="includes/chatsearch-inc.php" method="POST">
<input type="text" name="search" placeholder="Search a user or applicant\'s name">
<button name="submit"><i class="fa fa-search"></i></button>
</form>
<div>
</div>
</div>
and click the notifications tab, the notifications tab doesn't show anything, as in a clear white.
I managed to check every bit of my css, but I can seem to see any thing wrong, am I missing something? Thanks!
EDIT: I now know where the problem is. The problem is when I click the notifications tab, it doesn't switch the active class in DOM from inbox to notifications, and doesn't remove the active class from inbox. Without the said content inside the inbox, it works flawlessly. Why is that?
Source