Event Listener Duplication Debug
how do i ensure element is full height of window when scrolling down
how do i ensure element is full height of window when scrolling down
If you just need the element to always be the full height of the viewport:
.full-height {
height: 100vh; /* Full viewport height */
overflow: auto; /* Scrollable if content overflows */
}
If the element is inside a parent container, you may need:
html, body {
height: 100%;
margin: 0;
}
.container {
height: 100vh; /* Ensures it fills the viewport */
display: flex; /* Optional: for centering content */
align-items: center;
justify-content: center;
}
If the element’s height needs to dynamically adjust when the window resizes:
function setFullHeight() {
const element = document.querySelector('.full-height');
if (element) {
element.style.height = `${window.innerHeight}px`;
}
}
// Run on load and resize
window.addEventListener('load', setFullHeight);
window.addEventListener('resize', setFullHeight);
Alternative Fix: Using a Single Event Listener Instead of attaching an event listener to each .copy-code element, delegate it to the document:
document.addEventListener('keydown', e => {
let letter = e.key.toLowerCase()
if (letter == 'enter') {
if (e.target.classList.contains('copy-code')) {
e.preventDefault()
toggleImgVid(e)
return // Prevent further execution
}
toggleImgVid(e)
addTabIndexes(e)
}
})
This avoids multiple event listeners and prevents duplicate execution.
why is the following css not placing the .xbox at the end of the .task-container
<div class="project-container">
<div class="todo-app">
<h2>To-Do List <img src="images/list-icon-screenshot.png" alt=""></h2>
<div class="row">
<input type="text" id="input-box" placeholder="Add Task Here" value="clean kitchen">
<!-- ??? This Does NOT work with module scripts ??? -->
<!-- <button id="addBtn" onclick="addTask()">Add</button> -->
<button id="addBtn">Add</button>
</div>
<ul id="task-container">
<li id="task1" tabindex="0" class="checked"><span class="checkbox">o</span>Task 1</li>
<li id="task2" tabindex="0" ><span class="checkbox">o</span>task 2
<span class="xbox">x</span>
</li>
<li id="task3" tabindex="0" ><span class="checkbox">o</span>task 3 </li>
</ul>
</div>
</div>
#task-container {
display: flex;
flex-direction: column;
}
#task-container>li {
list-style: none;
font-size: 17px;
padding: 1px;
border: 1px solid black;
user-select: none;
cursor: pointer;
display: flex;
}
#task-container>li>.xbox {
justify-self: flex-end;
right: 0;
}
Your .xbox element is not aligning at the end of the .task-container because justify-self does not work on flex items unless their parent has display: grid. Since your li elements are using display: flex, you need to use margin-left: auto to push .xbox to the right.
Modify your CSS like this:
#task-container>li {
list-style: none;
font-size: 17px;
padding: 1px;
border: 1px solid black;
user-select: none;
cursor: pointer;
display: flex;
align-items: center; /* Ensure vertical alignment */
}
#task-container>li>.xbox {
margin-left: auto; /* Push the .xbox to the right */
}
Let me know if you need further refinements! 🚀
... (bottom of question)
Right now i am debugging, i currently have the following html, and the overflow-x to hidden and overflow-y to scroll on
#mainTargetDiv, but how do i get rid of the scrollbar for y visibility ?
For WebKit browsers (Chrome, Safari, Edge):
#mainTargetDiv {
overflow-y: scroll;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
}
#mainTargetDiv::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}
#mainTargetDiv::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}
You’ll have a scrollable #mainTargetDiv, but no visible scrollbar.