Home > Back-end >  Strikethrough text list, at mouse click
Strikethrough text list, at mouse click

Time:12-17

I need the strikethrough text with just the mouse click on the text. List css is outside form line margin I tried several methods and failed. I changed the code several times and I couldn't. I searched a lot on the site, but I didn't find a solution. I tried to solve it and I didn't find something to solve this problem

$(document).ready(function() {

  $('form').on('submit', function(e) {
    e.preventDefault();

    const listaDeTarefa = $('#lista-de-tarefa').val();
    const novoItem = $('<li></li>');

    $(`<li>${listaDeTarefa}</li>`).appendTo(novoItem);
    $(novoItem).appendTo('ul');
    $("li").click(function() {
      $(this).addClass("riscado");
    });
    $('#lista-de-tarefa').val("");
  });
});
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Roboto, sans-serif;
}

.container {
  margin: 100px auto;
  max-width: 640px;
  width: 100%;
}

form {
  margin-top: 40px;
}

input,
textarea,
button {
  display: block;
  padding: 8px;
  margin-bottom: 8px;
  width: 100%;
  resize: none;
}

button {
  background-color: #2e9ccc;
  border: none;
  text-transform: uppercase;
  color: #fff;
  font-weight: bold;
  font-size: 18px;
  font-style: italic;
  cursor: pointer;
}

button:hover {
  background-color: #18a9e9;
}

input:focus,
textarea:focus {
  outline-color: #18a9e9;
}

ul {
  text-decoration: line-through;
}
<!DOCTYPE html>
<html lang="pt-br">

<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>jQuery</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="main.css">
</head>

<body>
  <div >
    <header>
      <h1>Lista de tarefas</h1>
    </header>
    <form id="formulario">
      <input type="text" id="lista-de-tarefa" required /> <button type="submit">Cadastrar</button>
    </form>
    <div >
      <ul>
      </ul>
    </div>
  </div>
  <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
  <script src="./main.js"></script>
</body>

</html>

CodePudding user response:

There were some bugs, i commented on the spots:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Document</title>
    <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>jQuery</title>
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="main.css" />
  </head>

  <body>
    <div >
      <header>
        <h1>Lista de tarefas</h1>
      </header>
      <form id="formulario">
        <input type="text" id="lista-de-tarefa" required />
        <button type="submit">Cadastrar</button>
      </form>
      <div >
        <ul></ul>
      </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
    <script src="./main.js"></script>

    <script>
      $(document).ready(function () {
        //           
  • Related