Add HTML with Javascript and Remain

Asked

Viewed 61 times

-1

I want it to be possible to add and then when update the page it stays saved in my HTML.

.menu {
  width: 100%;
  height: 70px;
  background-color: #56B8BD;
  max-height: 70px;
}

.menu ul li {
  float: left;
  list-style: none;
  text-decoration: none;
  color: #FFF;
  font-size: 18px;
  font-weight: bold;
  padding-top: 1%;
}

button {
  width: 56px;
  height: 56px;
  border-radius: 56px;
  font-size: 18px;
  border: none;
  float: right;
  margin-right: 1%;
  margin-top: 0.25%;
}

button:hover {
  transform: scale(1.03);
}
<html>

<head>
  <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

  <style type="text/css">
  </style>

</head>

<body>
  <div class="principal">
    <nav class="menu">
      <ul>
        <li> Barra Menu</li>
      </ul>
    </nav>
    <button onclick="adicionar()">+</button>
  </div>

  <script>
    function adicionar() {
      $("body").append("<nav><ul><li> Novo Menu Adicionado</li></ul></nav>");
      $("nav").addClass("menu")
    }
  </script>

</body>

</html>

  • I don’t know if I understand, but you want this new div be added to your HTML file after generated?

  • 4

    You need to persist these changes somewhere, whether in database, localStorage, session, memory, disk file, etc, depends on your needs.

  • That would be it but I don’t know how to do it if you can help

  • How about localstorage? see if it works ai http://kithomepage.com/sos/addeddo.htm

1 answer

0


To configure your connection to Mysql Database in PHP:

<?php
   $db_name = "[Nome do seu banco]";
   $db_user = "[Nome de usuario do seu banco]";
   $db_password = "[Senha do banco]";
   $db_host = "[Host do banco]";

   $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

   if(!$conn)
        echo "Erro na conexão";

   //Para inserir a quantidade de DIV's
   $sql = "INSERT INTO [Nome da sua tabela] ([nome da coluna])
               VALUES ([valor a ser adicionado])";

   if ($conn->query($sql) === TRUE) {
      echo "Sucesso!";
   } else {
      echo "Error";
   }

   //Para buscar um valor no banco
   $sql = "SELECT * FROM [Nome da sua tabela]";
   $result = $conn->query($sql);

   //Dae voce usa a var result para manipular os dados do BD
?>

Browser other questions tagged

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