0
Hello! What I would like is that when my user click on "add cart" on page 1, an append is added on page 2.
Currently I have the append configured correctly on my page 2
HTML PAGE 1:
<button type="button" id="btnCompra" class="btn btn-danger">
<i class="fas fa-shopping-basket"></i> Adicionar ao carrinho</button>
HTML PAGE 2:
<div class="container-fluid divProdCarrinho">
<div class="row" id="modeloProdutos">
<div class="col-sm-12 col-md-4 col-lg-6">
<img src="img/arroz.jpg" id="imagenzinha">
<p id="descricaoProduto">...</p>
</div> </div> </div>
JAVASCRIPT (which works because all elements are from the same page):
$(document).ready(function(){
$('#botaoPagina1').click (function(){
var template = $('.divProdCarrinho').html();
$("#bodyPrincipal").append(template);
});
JAVASCRIPT (I would like it to work, where butonAdd is page 1 element)
$(document).ready(function(){
$('#botaoPagina2').click (function(){
var template = $('.divProdCarrinho').html();
$("#bodyPrincipal").append(template);
alert(template);
});
How so on "page 2"? it is only possible to do
append
on the page that is loaded in the browser. It was not clear how this navigation is, but you need to pass a parameter to the other page, by querystring for example, and append in the script of the page itself– Ricardo Pontual
Use the
localStorage
to pass data from one page to another.– Valdeir Psr
Ricardo basically I want to give an append on page 2 with elements of page 1, but I do not know if it is possible
– Weslley Fillipe
Valdeir is possible I save the elements in localStorage of page 1 and give an append with this information on page 2?
– Weslley Fillipe
@Weslleyfillipe with the
localStorage
yes. You save the HTML on one page, and by loading the other, you capture the saved HTML on the previous page.– Valdeir Psr
Valdeir, I tried to give a "localStorage.setItem('modeloProduto', $('.divProdCarrinho').html();" but returned "Undefined", since this div only exists on page 2. My goal was to add a div on page 2 after clicking the button on page 1
– Weslley Fillipe