6
How can I place certain images in a div using jquery by clicking the button?
Follows the html:
<div>
<button id="btn2015" class="btn">2015</button>
<button id="btn2014" class="btn">2014</button>
<button id="btn2013" class="btn">2013</button>
<button id="btn2012" class="btn">2012</button>
</div>
<div id="conteudo">
</div>
Depending on each button clicked, the contents div will be emptied and the images will be placed according to the button. Follow the names of the images:
imagem_piscina_2015.jpg
imagem_sala_2015.jpg
imagem_escrito_2015.jpg
Besides these, there are several others with the same names, only the years ending with the different years. How can I make each button, call only the images according to their respective years?
What have you ever tried to do?
– Zignd
i made a click event for each button. The first thing I did was to empty the contents div. Later I tried to get the name of the image that is in the same file directory, but without success. :(
– DiChrist
One image per button or 3 images per button?
– Sergio
use date attribute on buttons and put the URL of your SITE, something like:
<button id="btn2015" class="btn" data-img="/imgs/imagem_piscina_2015.jpg">2015</button>
, so in the event click, you read the attribute and an append in thediv#conteudo
, or already leaves an image there (with display:None), and changes src with jquery($("img").attr("src",link_img)
and has an effect on it to appear, withfadeIn(x)
where x is the time in MS.– Ale
in this case 3, but I’m trying to do it in a way that takes the word ending, if you click on the 2015 button, the images that end in 2015 appear, if it’s the 2014 button, the images that end in 2014 and so on
– DiChrist