0
insira o código aqui
I have a HTMLCollection
icon. I have the option to add a new text that comes with a new icon, in case increasing this HTMLCollection
.
need to make a ForEach()
on it to give 'life' to that button, I want it to hide or show the text.
Array.from('taldohtmlcollection').forEach
okay.
The question is when I add new text with a new icon. This new icon is added to HTMLCollection
, however the Array
does not update, that is, continues with the old items and does not receive this new icon. I need to fix this, so that it iterates between all the items of Array
, and add a new icon HTMLCollection
, it also passes to Array.
I hope I was clear.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="stylenote.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<div id="container0">
<header>
<h1>Note Manager</h1>
<form action="">
<input id="searchbar" type="text" placeholder="Search">
</form>
</header>
<main>
<div id="notes">
<ul>
<li class="linotes">
<a class="clickicon"><i class="fas fa-edit"></i></a>
<p class="titleofnotes">First Note</p>
<input type="text" class="inputnote" value="">
</li>
<li class="linotes">
<a class="clickicon"><i class="fas fa-edit"></i></a>
<p class="titleofnotes">Second Note</p>
<input type="text" class="inputnote" value="">
</li>
<li class="linotes">
<a class="clickicon"><i class="fas fa-edit"></i></a>
<p class="titleofnotes">Third Note</p>
<input type="text" class="inputnote" value="">
</li>
</ul>
</div>
<div id="hide-notes">
<label for="hide">Hide Notes</label>
<input id="hide" type="checkbox">
</div>
<div id="addnotes">
<label for="add">Add Note</label>
<input id="add" type="text">
<input type="submit" value="Add" id="btnadd">
</div>
</main>
</div>
</body>
<script src="notejs.js"></script>
</html>
CSS
body{
font-family: Arial, Helvetica, sans-serif;
}
ul{
margin: 0;
padding: 0;
list-style:none;
}
#container0{
margin:0% 20%;
background-color:floralwhite;
}
header{
padding:5%;
text-align: center;
background-color: #cccccc;
}
header input{
width: 28%;
}
#notes{
margin-left: 5%;
margin-bottom: 10%;
}
li input {
width: 85%;
}
#hide-notes label{
user-select: none;
}
#hide-notes label:hover{
background-color:#ccccff
}
#hide-notes input[type="checkbox"]{
display: none;
}
#addnotes{
text-align: center;
}
#btnadd{
background-color:rgb(13, 131, 48);
color: white;
width: 8%;
height: 30px;
border-radius: 10px;
font-size:16px;
}
.clickicon{
float: right;
cursor: pointer;
margin-right: 5%;
var lista = document.querySelector("ul");
var btnadd = document.getElementById("btnadd");
var addinput = document.getElementById("add");
btnadd.addEventListener('click', function (e) {
e.preventDefault();
if (addinput.value !== '') {
var newli = document.createElement("li");
var plist = document.createElement("p");
var inputlist = document.createElement("input");
var clickicon = document.createElement("clickicon");
var icon = document.createElement("i");
clickicon.className = 'clickicon';
icon.className = 'fas fa-edit';
lista.appendChild(newli);
newli.appendChild(clickicon);
clickicon.appendChild(icon);
newli.appendChild(plist);
plist.className = "titleofnotes";
newli.appendChild(inputlist);
inputlist.setAttribute("type", "text");
plist.textContent = addinput.value;
var searchbar = document.getElementById('searchbar');
var linotes = document.getElementsByClassName('linotes');
var searchbar.addEventListener('keyup', function (e) {
text = e.target.value.toUpperCase();
Array.from(linotes).forEach(function (note) {
console.log(note)
var litextp = note.textContent;
var capslitextp = litextp.toUpperCase();
if (capslitextp.indexOf(text) > -1) {
note.style.display = 'block'
}
else { note.style.display = 'none' }
})
})
I’ll edit and upload the code. the new element added to Htmlcollection, not me, is automatic depends on whether the user clilcates to open a new note. comes with the icone of the same class. Adding an item.
– Vitor Mendonça