-1

I want to ask, is there any way to change an image with text when i hover or click that image?

my code is :

<div class="container3">
        <h1 class="header3"><font color="white">Tentang Kami</h1>
            <div class="content2">
                <img src="about.png" align="center" class="gambar3">
            </div>
</div>

2 Answers2

0

See the below example onclick event.

.container3
{
background:black;
}
#content 
{
color:white;
}
<div class="container3">
    <h1 class="header3"><font color="white">Tentang Kami</font></h1>
                <div class="content2" id="content">
                    <img src="about.png" align="center" class="gambar3" onclick="img_click()" />
                </div>
    </div>

    <script>
    function img_click(){
    document.getElementById("content").innerHTML = "Image Clicked";
      }
    </script>
bhansa
  • 7,282
  • 3
  • 30
  • 55
0

Simplest way is to toggle visibility of an image and a sibling text.

$(".hover").mouseover(function() {
  $(this).find('img').hide();
  $(this).find('.text').show();
}).mouseleave(function() {
  $(this).find('img').show();
  $(this).find('.text').hide();
});

$(".click").click(function() {
  $(this).find('img').toggle();
  $(this).find('.text').toggle();
});
.hover,
.click {
  width: 200px;
  height: 200px;
  margin-right: 10px;
  float: left;
  overflow: hidden;
}

.hover .text,
.click .text {
  display: none;
}

.hover .text,
.click .text {
  line-height: 200px;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content2 hover">
  <img src="https://www.qvb.com.au/images/phocagallery/thumbs/phoca_thumb_l_sample-200x200.png" align="center" class="gambar3">
  <p class="text">Demo Text</p>
</div>

<div class="content3 click">
  <img src="https://www.qvb.com.au/images/phocagallery/thumbs/phoca_thumb_l_sample-200x200.png" align="center" class="gambar3">
  <p class="text">Demo Text</p>
</div>
Dan Philip Bejoy
  • 4,321
  • 1
  • 18
  • 33