How can I maintain on the page a dynamically created component with jQuery?

0

How to keep a dynamically created element on page with jQuery? When I refresh or go back to the page, the element is removed.

    
asked by anonymous 25.04.2017 / 14:21

1 answer

0

Using jQuery you can manipulate the element when creating the page, for example:

$(document).ready(function() {
    $("#minhaDiv").html('<div id="NovaDiv"></div>');
    $("#minhaDiv").append('<div id="OutraDiv"></div>');
});

Using pure javascript:

<script type="text/javascript">
   function carregarDados() {
      var divSelecionada = document.getElementById('minhaDiv');
      divSelecionada .innerHTML = '<ol><li>Lista de Exemplo</li></ol>';
   }
</script>

<body onload="carregarDados();">
    <div id="minhaDiv"></div>
</body>
    
25.04.2017 / 15:57