I’m just a twelve year old that just got into coding last year, I am starting this specific part of a project that involves the user clicking a button with class: add_button to create a div that is the file for storing information, all the functions in the user created files are functional except for one,
function delete_file() {
const deleted_file = event.target.parentNode;
deleted_file.remove();
}
It turns out during testing, it only deletes the latest div/file that was created, I later made it so that it doesn’t have remove() but instead change the border which works for some reason.The full code is here.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LanguageMaker3000</title>
<link rel="stylesheet" href="LanguageMaker3000.css">
</head>
<body>
<script src="LanguageMaker3000.js"></script>
<section class="top_nav">
<p class="main_title"><u>LanguageMaker3000</u></p>
<p class="word"><u>Robosteyr</u></p>
<p class="wordt"><u>derewaq</u></p>
<p class="wordg"><u>mmuytr</u></p>
<p class="wordi"><u>sacter</u></p>
<p class="wordj"><u>sabbydabby</u></p>
<p class="wordp"><u>cocou</u></p>
<p class="words"><u>piuyttt</u></p>
<input type="text" placeholder="Search Files..." class="folder_searcher">
<button type="button" class="search_button">Y</button>
<div class="scroll_image">
<p class="about_us"><u>About Us</u></p>
<p class="about_us_paragraph">Hi! I'm Matt and I proudly present the LanguageMaker3000(Although there aren't 2999 more versions of this)!Language has been around for more than 1 million years and
is the root of every famous civilizations such as Ancient Egypt and Greece.This is a goofy website that allows you to create your own languages!:)
</p>
</div>
<div class="seperator"></div>
</section>
<section class="content">
<div class="add_bar"></div>
<button class="add_button" onclick="create_file()"><b>+</b></button>
<p class="num_file_text">Current Files:</p>
<div class="number_list">
<div class="number_list_r">
<p class="starting_num">0</p>
</div>
</div>
<div class="file_query">
</div>
</section>
</body>
</html>
CSS:
body {
overflow-x: hidden;
}
button {
cursor: pointer;
}
.top_nav {
position: sticky;
background-color: mediumspringgreen;
width: 200pc;
height: 6pc;
margin-left: -34px;
margin-top: -35px;
border-bottom: 5px solid yellow;
}
.main_title {
position: relative;
top: 20px;
left: 50px;
color: yellow;
z-index: 2;
font-size: 200%;
font-family: fantasy;
}
.word {
position: relative;
top: -4pc;
left: 400px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
}
.wordt {
position: relative;
top: -4pc;
left: 400px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
}
.wordg {
position: relative;
top: -9pc;
left: 550px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
}
.wordi {
position: relative;
top: -14pc;
transform: rotate(2deg);
left: 700px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
width: 12px;
transform: rotate(90deg)
}
.wordj {
position: relative;
top: -15pc;
left: 900px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
}
.wordp {
position: relative;
top: -20.7pc;
left: 800px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
width: 12px;
transform: rotate(90deg)
}
.words {
position: relative;
top: -24.5pc;
left: 1050px;
color: yellow;
z-index: 5;
font-size: 150%;
font-family: fantasy;
width: 12px;
}
.folder_searcher {
position: relative;
z-index: 5;
left: 64pc;
top: -25.6pc;
width: 23pc;
height: 35px;
border: 3px solid black;
}
.search_button_text {
position: relative;
top: -29.4pc;
left: 95.7pc;
z-index: 2;
font-size: 90%;
font-family: fantasy;
}
.search_button {
position: relative;
top: -25.6pc;
border-top-right-radius: 25%;
border-bottom-right-radius: 25%;
right: -63.5pc;
background-color: #90ee90;
width: 50px;
height: 43px;
border: 2px solid black;
cursor: pointer;
}
.top_nav:hover .search_button {
background-color: yellowgreen;
}
.scroll_image {
position: absolute;
top: 6.4pc;
height: 193px;
width: 150pc;
background-image: linear-gradient(180deg, rgba(107, 87, 88, 0.7), rgba(253, 253, 253, 0.9)), url("https://indianapublicmedia.org/large-images/amos-images/isaiah-scroll.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
overflow:scroll;
}
.seperator {
margin-top: -12.2pc;
height: 12px;
background-image: linear-gradient(90deg, rgba(178, 255, 89, 0.5), rgba(37, 58, 124, 0.5));
}
.about_us {
color: white;
font-size: 200%;
font-family:'Courier New', Courier, monospace;
margin-left: 45pc;
}
.about_us_paragraph {
color: white;
font-size: 200%;
margin-left: 50px;
width: 90pc;
font-family:'Courier New', Courier, monospace;
}
.add_bar {
margin-top: 13pc;
margin-left: -12px;
width: 230pc;
height: 50px;
background-color: rgb(233, 232, 232);
border-bottom: 3px solid grey;
}
.add_button {
position: relative;
top: -46px;
margin-left: 78pc;
width: 40px;
height: 40px;
border-radius: 50%;
}
.content:hover .add_button {
background-color: grey;
}
.num_file_text {
position: relative;
margin-top: -28.5pc;
top: 23pc;
color: rgb(14, 204, 204);
font-size: 150%;
font-family: 'Courier New', Courier, monospace;
}
.number_list {
margin-top: 21.5pc;
margin-left: 13pc;
width: 350px;
height: 30px;
background-color: white;
border-radius: 12%;
overflow: hidden;
}
.number_list_r {
height: 90px;
padding-top: 1px;
}
.starting_num {
position: relative;
top: -12px;
}
.file_query {
border: 1px solid rgb(214, 212, 212);
margin-top: 0.8pc;
margin-left: -12pc;
width: 250pc;
height: 290pc;
background-image: linear-gradient(180deg, rgb(255, 255, 255), rgba(0, 0, 0, 0.5)), url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTHCBd8-57JaK_VsnXDjo61aL-3AkwM7TpLN-w7-Vaa&s");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
background-position: center;
}
.filebase:hover .okbutton {
background-color: yellowgreen;
}
.filebase:hover .openbutton {
background-color: yellowgreen;
}
.filebase:hover .deletebutton {
background-color: yellowgreen;
}
.filebase:hover .renamebutton {
background-color: yellowgreen;
}
button {
cursor: pointer;
}
JS:
//Create New File
function create_file() {
const file_query = document.getElementsByClassName("file_query")[0];
const file_base = document.createElement("div");
const file_name = document.createElement("input");
const ok_button = document.createElement("button");
const open_button = document.createElement("button");
const rename_button = document.createElement("button");
const delete_button = document.createElement("button");
file_base.setAttribute("style", "margin-left: 28pc; margin-top: 4pc; width: 66pc; height: 5pc; border: 5px outset grey; background-color: rgb(182, 180, 180);");
file_base.setAttribute("class", "file_base_t");
file_name.setAttribute("style", "position: absolute; margin-top: 1.45pc; margin-left: 1pc; height: 30px; width: 340px;");
file_name.setAttribute("class", "id_collector");
file_name.setAttribute("placeholder", "File Name...");
file_name.addEventListener("input", no_border)
file_base.appendChild(file_name);
ok_button.setAttribute("style", "position: absolute; font-family: fantasy; margin-top: 1.4pc; margin-left: 22.5pc; height: 35.5px; width: 50px; border-top-right-radius: 25%; border-bottom-right-radius: 25%; background-color: #90ee90;");
ok_button.setAttribute("class", "ok_button_t");
ok_button.textContent = "Y";
ok_button.addEventListener("click", addId);
file_base.appendChild(ok_button);
open_button.setAttribute("style", "position: absolute; font-family: fantasy; margin-left: 9pc; margin-top: 19px; height: 50px; width: 70px; background-color: #90ee90; display: none; pointer-events: none;");
open_button.setAttribute("class", "open_button_t");
open_button.textContent = "Open";
open_button.addEventListener("click", open_dictionary);
file_base.appendChild(open_button);
rename_button.setAttribute("style", "position: absolute; font-family: fantasy; margin-left: 52pc; margin-top: 17px; height: 50px; width: 70px; background-color: #90ee90; display: none; pointer-events: none;");
rename_button.setAttribute("class", "rename_button_t");
rename_button.textContent = "Rename";
rename_button.addEventListener("click", rename_id);
file_base.appendChild(rename_button);
delete_button.setAttribute("style", "position: absolute; font-family: fantasy; margin-left: 60pc;width: 70px;height: 50px; margin-top: 16px; background-color: #90ee90;");
delete_button.setAttribute("class", "delete_button_t");
delete_button.textContent = "Delete";
delete_button.addEventListener("click", delete_file);
file_base.appendChild(delete_button);
file_query.appendChild(file_base);
}
function addId() {
const id_parent = event.target.parentNode;
const y_no = id_parent.querySelector(":nth-child(2)")
const id_input = id_parent.querySelector(":nth-child(1)");
const open_ok = id_parent.querySelector(":nth-child(3)");
const rename_ok = id_parent.querySelector(":nth-child(4)");
let id_value = id_input.value;
if (id_value == "") {
id_input.style.border = "3px solid red";
} else {
id_parent.setAttribute("id", id_value);
id_input.style.display = "none";
id_input.style.pointerEvents = "none";
y_no.style.display = "none";
y_no.style.pointerEvents = "none";
open_ok.style.display = "block";
open_ok.style.pointerEvents = "auto";
rename_ok.style.display = "block";
rename_ok.style.pointerEvents = "auto";
}
}
function open_dictionary() {
window.location.replace("http://127.0.0.1:5500/LanguageStorage.html")
}
function rename_id() {
const renamed_button = event.target.parentNode;
const open_no = renamed_button.querySelector(":nth-child(3)");
const rename_no = renamed_button.querySelector(":nth-child(4)");
const ok_ok = renamed_button.querySelector(":nth-child(2)");
const input_ok = renamed_button.querySelector(":nth-child(1)");
open_no.style.display = "none";
open_no.style.pointerEvents = "none";
rename_no.style.display = "none";
rename_no.style.pointerEvents = "none";
ok_ok.style.display = "block";
ok_ok.style.pointerEvents = "auto";
input_ok.style.display = "block";
input_ok.style.pointerEvents = "auto";
}
function delete_file() {
const deleted_file = event.target.parentNode;
deleted_file.remove();
}
function no_border() {
event.target.parentNode.querySelector(":nth-child(1)").style.border = "none";
}
I will be happy to accept any solutions/alternatives to my issue.Thx.
…………………………………………………………………………………….