How to concatenate without changing the existing content

Asked

Viewed 27 times

-1

My goal is that by clicking the gray button adding a postit without changing what is already there, using the loop and += to concatenate will change what is already there, I wonder if there are any other options to concatenate using the loop without any changes

function enable() {
  document.querySelector('.btn-escrever').disabled = false;
}

var btn = document.querySelector(".btn-apagar");
btn.addEventListener("click", remove);
var textotitle = document.querySelector(".tarefas");

function remove() {
  textotitle.parentNode.removeChild(textotitle);
}
* {
  margin: 0;
  padding: 0;
  line-height: 1;
  box-sizing: border-box;
  /* outline: 1px solid tomato; */
  border-collapse: collapse;
  border-spacing: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.emcima {
  max-width: 64rem;
  margin: 0 auto;
}

.espaco {
  margin-top: 20px;
}

body {
  background-color: #eaeaea;
  padding: 20px;
}

button {
  cursor: pointer;
}

h1 {
  font-size: 18px;
  text-transform: uppercase;
}

ul {
  padding: 0;
  list-style: none;
}

.A {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #aaa;
}

.titulo {
  background-color: transparent;
  border: 0;
  border-bottom: 1px solid #666;
  margin-right: 10px;
  display: inline;
}

.btn-mais {
  border: 0;
  color: #111111;
  padding: 5px 10px;
  border: 1px solid #999999;
  border-radius: 6px;
  display: inline-block;
}

header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.tarefa {
  background-color: yellow;
  padding: 10px;
  max-width: 300px;
}

.btn-escrever,
.btn-apagar {
  border: 0;
  background-color: transparent;
  padding: 3px 5px;
}

textarea {
  width: 100%;
  background-color: yellow;
  border: 0;
}
<div class="emcima">
  
<div class='A'>
    <h1>Tarefas</h1>
    <button type="button" class="btn-mais">Adicionar</button>
</div>
    <div class='espaco'>
    <ul class="tarefas">
      
      <li class="tarefa">
        
        <header>
          <input type="text" class="titulo" placeholder="Título">
          <button type="button" onclick="enable()" class="btn-escrever">✒️</button>
          <button type="button" class="btn-apagar">✂️</button>
        </header>
        <textarea name="" placeholder="Texto da tarefa" class='texto'></textarea>
      </li>
    </ul>
    </div>
</div>

1 answer

0

1 - the var textotitle should be within the remove function

2 - I think I’ve lived in jquery, but that would be it with him:

$('.tarefa').eq(0).clone().appendTo('.tarefas');

but I would change the tasks to id and not class because I believe there is no more than one class with this name

Browser other questions tagged

You are not signed in. Login or sign up in order to post.