5
I need to pass the value of a function according to the clicked value of it. There are 3 Divs, each one is a gallery. I need that when clicking on the "see more" option, open a page with all the photos only from that gallery, however, I do not know how to pass the value of the clicked gallery, just assign the same right in the code. Could they help? I load the function through the body onload
on the targeted page, I don’t know if it’s the best way...
The gallery:
while(x <= 3){
imgs.innerHTML += "<div id='gal"+x+"' class='row'>";
imgs.innerHTML += "<div class='eight columns'>";
imgs.innerHTML += "<h4>Galeria "+x+"</h4>"
for(var i = 0; i <= 3; i++){
galeria[i] = "foto"+x+"_"+(i+1)+".jpg";
}
for(var i = 0; i < galeria.length; i++){
imgs.innerHTML += "<img src='img/"+galeria[i]+"' class='imgs-galeria'>";
}
imgs.innerHTML += "</div>";
imgs.innerHTML += "</div>";
imgs.innerHTML += "<a href='teste.html'><div id='link'><p>Veja mais</p></div>";
x++;
}
The page teste.html
:
<body onload="maisGaleria(2);">
<div class="center">
<div class="row">
<div class="four columns top">
<h5>Nome</h5>
</div>
<div class="eight columns menu">
<ul>
<a href="index.html"><li><h4 class="menu-list">Home</h4></li></a>
<a href="galeria.html"><li><h4 class="menu-list">Galeria</h4></li></a>
<a href="sobre.html"><li><h4 class="menu-list">Sobre</h4></li></a>
<a href="contato.html"><li><h4 class="menu-list">Contato</h4></li></a>
</ul>
</div>
</div>
<div class="row galeria">
<div id="gallery" class="container">
</div>
</div>
<div class="row">
<div id="footer">
<div class="four columns">
<h4>Nome</h4>
</div>
<div class="eight columns img-footer" id="social">
</div>
</div>
</div>
</div>
and the function maisGaleria(n)
:
function maisGaleria(n){
var galeria = new Array();
var img = $("#gallery");
img.innerHTML = "<div class='row'>";
img.innerHTML = "<div class='six columns'>";
//imgs.innerHTML += "<h4>Galeria"+n+"</h4>";
for(var i = 0; i <= 3; i++){
galeria[i] = "foto"+n+"_"+(i+1)+".jpg";
}
//se utilizar <=galeria.length, ele adicionara um valor vazio, que foi atribuido devido ao (i+1) do outro for.
for(var i = 0; i < galeria.length; i++){
img.innerHTML += "<img src='img/"+galeria[i]+"' class='imgs-galeria'>";
}
img.innerHTML += "</div>";
img.innerHTML += "</div>";
}
thanks ! But the page keeps opening without any image. I did not understand exactly what was done, maybe understanding better I can turn around. I did not understand the function opens Anela and where I should use it, I did not understand the variable img of the function moreGaleria and did not understand how and what I should pass as parameter newElemento. Would you please explain ?
– Gabriel Ozzy
I wonder exactly because with this code it returns that "img is null"...
– Gabriel Ozzy
@Gabrielozzy sometimes I’m at Sopt during work and kind of distracted. There was an error in my answer, the element I created was
img
and should bediv
for#gallery
is adiv
also, and incidentallyimg
no innerHTML. Now fixed.– Sergio
Thanks again for your help. However, it still doesn’t work... I put the two functions in the file pgScript.js and removed the onload from the body on the test page.html. I wonder what it might be ?
– Gabriel Ozzy
But I apologize for the ignorance, it also happens that I live in a huge rush. Now I understand the functions and how they work, but how would I pass the function parameter opens dynamically ? I mean, without typing right into the code ?
– Gabriel Ozzy
managed to solve my problem, I will post the answer here soon ! Thank you for the attention !
– Gabriel Ozzy