0
How to keep an element dynamically created with jQuery on the page? When I refresh or return to the page, the element is removed.
0
How to keep an element dynamically created with jQuery on the page? When I refresh or return to the page, the element is removed.
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>
Browser other questions tagged jquery
You are not signed in. Login or sign up in order to post.
You have to change your logic and not load the whole page. A refresh always clears HTML and Javascript.
– Sergio
Do you know how I can do that? I’m starting with js/jQuery.
– Emerson Vieira
Take a look here: https://answall.com/q/6626/129, it’s a good start
– Sergio
thanks, but it’s still not what I’m looking for. I’m using append to create cards materialize from the click of a page button.
– Emerson Vieira
And why you need to refresh the page?
– Sergio
is pq after created, the Component(card) needs to be saved on the page and it will be fed with information obtained via ajax, but when refreshing and changing page and coming back, the cards disappear, so wanted a way to keep them. cards can be created and deleted.
– Emerson Vieira
Why not send the data to recreate these "cards" by ajax as well? so when you open the page again you can recreate them
– Sergio
is a good idea! I’ll try this. obg.
– Emerson Vieira
This is one of the ideas (and usual solution) that is suggested in this other question I mentioned. So you know you have what’s important on the server and you can recreate in milliseconds when the page loads or the user goes back to the page. Like a "shopping cart" before it’s complete.
– Sergio