← Desenvolvimento

Clicar numa imagem para aparecer imagem

Lida 1578 vezes

Offline

fpdeus 
Membro
Mensagens 1289 Gostos 0
Feedback +42

Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 1000 Posts

Boas,

Queria saber qual o código para que ao utilizador clicar numa imagem, aparecesse outra imagem.

Ou seja, tenho um botão (imagem) a dizer "VER CÓDIGO", e ao clicar, aparecia no mesmo sitio outra imagem.

Acho que me fiz a entender

Alguém sabe?
Offline

Bruno Mota 
Membro
Mensagens 1733 Gostos 3
Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

procura por javascript onclick
Offline

Jeckerson 
Membro
Mensagens 34 Gostos 0
Feedback +1

Troféus totais: 22
Trófeus: (Ver todos)
Level 5 Level 4 Nineth year Anniversary Eighth year Anniversary Super Combination Combination Topic Starter Poll Voter Level 3 Level 2

Se te serve em jQuery entao ve isso:

jQuery
Código: (javascript) [Seleccione]
function show_img()
{
   var another_img = '/images/another_img.jpg';
   $("img#click").attr('src', another_img);
}

//ou, mas entao nao precisas de onclick="" em img tag

$(document).ready(function() {
   var another_img = '/images/another_img.jpg';
   $("img#click").click(function(){
        $(this).attr('src', another_img);
});
});

e HTML
Código: (html4strict) [Seleccione]
<img id="click" onclick="show_img()" src="/images/first_img.png" alt="Show Code" title="Show code" />