Is there a way to use the outerHTML method on a parent element to append a child element so that the icons appear outside of the targeted element rather than inside it? The current code snippet shows the icons inside the box, but I want them to be placed outside of it. I have tried using flex and other CSS properties without success.
//on select
const deleteExisting = document.querySelectorAll('.solidOnClickDelete');
// Item Lists
const itemRows = document.querySelectorAll('.drag-item-list');
const mondayList = document.getElementById('mondaylist');
// Items
let updateOnLoad = false
// Initialize Arrays
let mondayListArray = [];
let listarrays = [];
// Drag Functionality
let dragged;
let updateRow = false;
let dragging = false;
let currentRow;
// Get Arrays from localStorage if available, set default values if not
function getSavedRows() {
mondayListArray = ['Work 7.00-15.00', 'Doctor visit'];
}
// Set localStorage Arrays
function updateSavedRows() {
listarrays = [mondayListArray];
const arrayNames = ['monday']
arrayNames.forEach((arrayName, index) => {
//localStorage.setItem(`${arrayName}Items`, JSON.stringify(listarrays[index]))
});
}
//Filter to remove null from deleted items //
function filterArray(array) {
const filteredArray = array.filter(item => item !== null);
return filteredArray;
}
// Create DOM Elements for each list item
function createItemEl(rowEl, row, item, index) {
// List Item
const listEl = document.createElement('li')
listEl.classList.add('day-item');
listEl.textContent = item;
listEl.draggable = true;
listEl.setAttribute('ondragstart', 'drag(event)')
listEl.contentEditable = true;
listEl.id = index;
const divOptions = document.createElement('span');
divOptions.classList.add('father', 'hidden');
divOptions.contentEditable = false;
listEl.onfocus = () => divOptions.classList.remove('hidden');
listEl.onblur = () => divOptions.classList.add('hidden');
const iconDelete = document.createElement('i');
const iconYes = document.createElement('i');
iconYes.classList.add('far', 'fa-check-circle', 'fa-2x');
iconDelete.classList.add('far', 'fa-times-circle', 'fa-2x');
iconYes.setAttribute('onclick', `updateItem(${index}, ${row})`);
iconDelete.setAttribute('onclick', `deleteItemOnClick(${index}, ${row})`);
//Append everything //
rowEl.appendChild(listEl);
listEl.appendChild(divOptions);
divOptions.appendChild(iconYes);
divOptions.appendChild(iconDelete);
};
// Update Columns in DOM - Reset HTML, Filter Array, Update localStorage
function updateDOM() {
// Check localStorage once
if (!updateOnLoad) {
getSavedRows();
}
mondayList.textContent = '';
mondayListArray.forEach((mondayitem, index) => {
createItemEl(mondayList, 0, mondayitem, index);
});
mondayListArray = filterArray(mondayListArray)
updateOnLoad = true;
updateSavedRows();
}
// Delete on click - //
function deleteItemOnClick(id, row) {
//let deleteItem = document.getElementsByClassName('solidOnClickDelete');
const selectedArray = listarrays[row];
delete selectedArray[id]
/*
deleteItem[0].onclick = function () { delete selectedArray[id] };
console.log(deleteItem[0]);
updateDOM();*/
updateDOM();
};
// add To Task Array
function addToRow(row) {
const itemText = addTask[row].textContent;
const selectedArray = listarrays[row];
selectedArray.push(itemText);
addTask[row].textContent = '';
updateDOM();
}
// reBuild Arrays
function rebulidArrays() {
mondayListArray = [];
for (i = 0; i < mondayList.children.length; i++) {
mondayListArray.push(mondayList.children[i].textContent);
}
updateDOM();
}
// On Load
updateDOM();
html {
box-sizing: border-box;
}
:root {
/* Light Theme Default */
/* Main Colors */
--primary-color: rgb(255, 255, 255);
--primary-variant: #b9b9b9;
--secondary-color: #5c5c5c;
/* Text on Main Colors */
--on-primary: rgb(54, 54, 54);
--on-background: rgb(78, 78, 78);
--on-background-alt: rgba(253, 253, 253, 0.952);
/* Background */
--background: rgb(255, 255, 255);
/* Box Shadow */
--box-shadow: 0 5px 20px 1px rgba(54, 54, 54, 0.5);
}
[data-theme="dark"] {
--primary-color: rgb(39, 39, 39);
--primary-variant: #777777;
--secondary-color: #e4e4e4;
--on-primary: rgb(173, 173, 173);
--on-background: rgba(255, 255, 255, 0.9);
--on-background-alt: rgba(0, 0, 0, 0.7);
--background: #202020;
}
body {
margin: 0;
color: var(--on-primary);
background-color:var(--primary-color);
font-family: 'Quicksand', sans-serif;
}
.slider.round::before {
border-radius: 50%;
}
.main-title {
font-size: 3rem;
color: var(--on-background);
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.main-container {
margin: 20px;
}
.days-list {
display: flex;
flex-direction:column;
}
/* rows / poulation */
.day-row,.populating-btns {
margin: 10px 10px;
background-color: rgba(95, 95, 95, 0.4);
border-radius: 3px;
display: flex;
overflow-x: hidden;
flex-wrap: wrap;
}
.dayFunction {
align-content: center;
justify-content: center;
margin-top: auto;
margin-bottom: auto;
}
.Flex-right {
display: flex;
float: right;
}
.Monday-row .header,
.Monday-row .over {
background-color: var( --on-primary);
}
.hidden {
display: none;
}
.day-item {
margin: 10px;
padding: 10px;
height: fit-content;
background-color:var(--secondary-color);
color: var(--primary-color);
border-radius: 3px;
line-height: 1.5rem;
letter-spacing: 1px;
cursor: pointer;
transition: 1s;
}
.day-item:focus {
outline: none;
background-color: white;
color: black;
}
/* Add Button Group */
.add-btns {
display: flex;
justify-content: space-between;
}
.add-btn {
margin: 10px;
padding: 5px 10px;
display: flex;
align-items: center;
cursor: pointer;
width: fit-content;
border-radius: 5px;
transition: all 0.3s ease-in;
user-select: none;
}
.add-task {
margin: 10px;
padding: 5px 10px;
display: flex;
align-items: center;
cursor: pointer;
width: fit-content;
border-radius: 5px;
transition: all 0.3s ease-in;
user-select: none;
background-color:var(--on-primary);
color:var(--on-background-alt);
}
.add-btn,.add-task:hover {
background-color: rgba(255, 255, 255, 0.9);
color: black;
}
.add-btn:active {
transform: scale(0.97);
}
.add-btn-extend {
margin: 10px;
padding: 10px 40px 10px 40px;
display: flex;
align-items: center;
cursor: pointer;
border-radius: 5px;
transition: all 0.5s ease-in;
user-select: none;
background-color: rgba(12, 178, 207, 0.603);
}
.add-btn-extend:hover {
background-color: rgba(255, 255, 255, 0.9);
color: black;
}
.solidOnClick , .solidOnClickDelete {
margin: 10px;
padding: 5px 10px;
align-items: center;
cursor: pointer;
width: fit-content;
border-radius: 5px;
transition: all 0.3s ease-in;
user-select: none;
background-color: var(--primary-variant);
}
.solidonclick:hover{
transition: all 0.5s ease-in;
filter: brightness(95%);
color: rgb(0, 0, 0);
background-color: rgba(228, 228, 228, 0.842);
}
.father {
display: flex;
justify-content: space-between;
}
.fa-check-circle {
color: green;
}
.fa-times-circle {
color: red;
}
.hidden {
display: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.1/css/all.css"
<link rel="stylesheet" href="style.css">
</head>
<body>
<li class="day-row Monday-row">
<div id="Mondaycontent">
<ul id="mondaylist" class="drag-item-list Flex-right" ondrop="drop(event)" ondragover="dropin(event)"
ondragenter="dragenter(0)">
</ul>
</div>
</div>
<!--Add Task To Li Later showInputBox()-->
<div class="add-container">
<div class="add-item" contenteditable="true"></div>
</div>
</li>
</body>
<script src="js.js"></script>
</html>