Change picture when hovering with mouse

Albin Karlsson

Good morning world! I've got another problem with my project, this time the JavaScript isn't working, I want the picture to change when I'm holding my mouse pointer over it, thanks for your patience!

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="mystyle.css" type="text/css" />
    <title>Konst UF</title>
    <meta charset="utf-8" />
    <script type="text/javascript" language="javascript">
      if (screen.width <= 699) {
        document.location = "mobile.html";
      }

      document.getElementById("Orderbutton").onclick = function () {
        location.href = "http://www.youtube.com/";
      };

      function billFunction() {
        var Bill = getElementById("BillGate");
        if (img.src.match("Bill")) {
          img.src = "bill-gates.jpg";
        } else {
          img.src = "Card.jpg";
        }
      }
    </script>
    <body>
      <p class="madeby">Made by Albin Karlsson and Oliver Jansson</p>
      <center>
        <ul>
          <li>
            <a href="index.html"><p class="Home">Home</p></a>
          </li>
          <li>
            <a href="#"><p class="Products">Products</p></a>
          </li>
          <li>
            <a href="#"><p class="About">About Us</p></a>
          </li>
        </ul>
      </center>
      <center><p class="para1">Konst UF</p></center>
      <center>
        <img
          id="BillGate"
          src="bill-gates.jpg"
          alt="Bill Gates"
          class="Billgates"
          onmouseover="billFunction()"
        />
      </center>
      <marquee><h2>Bill GATES</h2></marquee>
      <div></div>
      <div class="sidepanels1">
        <center>
          <img class="Konstbild" src="Konst_uf_1.jpg" alt="Konst" />
        </center>
        <h2>Unknown</h2>
        <p>I have no idea haha</p>
      </div>
      <div class="sidepanels2">
        <center>
          <img class="Konstbild" src="mikrofiberduk-konst.jpg" alt="Monalisa" />
        </center>
        <center><h2>Mona Lisa</h2></center>
        <center>
          <p>Mona Lisa is a painting which was painted by Leonardo Da Vinci</p>
        </center>
      </div>
      <center>
        <button
          id="Orderbutton"
          type="button"
          onclick="location.href = 'http://www.youtube.com/';"
        >
          Order Our Products
        </button>
      </center>
    </body>
  </head>
</html>

That was the html code and I hope you could find the problem, if you need the css I got it too:

body {
  background-color: grey;
  border: grey solid 1px;
}

p.para1 {
  margin: auto;
  width: 40%;
  border: 3px solid black;
  padding: 20px;
  background-color: black;
  color: white;
  font-size: 30px;
}
div.sidepanels1 {
  border: 5px dotted green;
  background-color: grey;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 320px;
  height: 550px;
  text-align: center;
  margin-top: 40px;
}
div.sidepanels2 {
  border: 5px dotted green;
  background-color: grey;
  position: absolute;
  top: 10px;
  left: 10px;
  width: 320px;
  height: 550px;
  margin-top: 40px;
}
p.iframe {
  position: absolute;
  top: 20px;
  text-align: center;
}
div.2nd {
  background-color: black;
  color: white;
}
img.asus-logo {
  width: 1200px;
  margin-left: auto;
  margin-right: auto;
  border: 2px solid black;
}
img.Billgates {
  margin-top: 30px;
  border: 2px solid black;
  margin-bottom: 40px;
}
img.Konstbild {
  margin-top: 20px;
  width: 300px;
  height: 300px;
  border: 3px solid green;
  margin-right: auto;
  margin-left: auto;
}
ul {
  list-style-type: none;
}
p.madeby {
  position: fixed;
}

Thank you !

Jose Serodio

In your JavaScript change this

    function billFunction(img) {
        var Bill = document.getElementById('BillGate');
        if (img.src.match("Bill")) {
            img.src = "bill-gates.jpg";
        } else {
            img.src = "Card.jpg";
        }
    }

And in your HTML

<img id="BillGate" src="screenshot_tweet.png" alt="Bill Gates" class="Billgates" onmouseover="billFunction(this)"/>

Also you should comment the onclick code before, it's causing you problems.

A better solution would be to do this only with CSS. It's much easier.

#bill {
    background-image: url("bill-gates.jpg");
}

#bill:hover {
    background-image: url("Card.jpg");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change picture by hovering over text

From Dev

Change picture on mouse click

From Dev

Why does the <li> element not change color and width when I hover the mouse over it after hovering over the image?

From Dev

In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

From Dev

Disable mouse EventListener when hovering a Google Map

From Dev

Show buttons just when the mouse is hovering the table

From Dev

restart image gallery when mouse is not hovering

From Dev

Effect when the mouse over the picture

From Dev

How to display a button over a picture only when hovering it?

From Dev

How can I make text appear when hovering a picture that has already the hovering for transform?

From Dev

How to show a large size of an picture when the mouse is on it?

From Dev

Change background color of row when hovering

From Dev

Change cursor when hovering a child window

From Dev

Change image color when hovering over li

From Dev

Change colors of spans when hovering parent div

From Dev

Prevent cursor to change when not hovering on Text - CSS

From Dev

Change css class when hovering html element

From Dev

Change background of the parent when hovering a child element

From Dev

Change cursor when hovering a child window

From Dev

Change colors of spans when hovering parent div

From Dev

Change image when hovering over a list of text

From Dev

Image shade change when hovering not working

From Dev

Change SVG When Hovering Menu In Bootstrap?

From Dev

Tooltip message when hovering on cell with mouse in wx.grid wxpython

From Dev

Display message when hovering over something with mouse cursor in Python

From Dev

Hover animation stops immediately when the mouse is no longer hovering over it?

From Dev

Multiple images depending on mouse location when hovering over div

From Dev

Display message when hovering over something with mouse cursor in Python

From Dev

Black squares that goes away when hovering mouse or clicking on it

Related Related

  1. 1

    Change picture by hovering over text

  2. 2

    Change picture on mouse click

  3. 3

    Why does the <li> element not change color and width when I hover the mouse over it after hovering over the image?

  4. 4

    In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

  5. 5

    Disable mouse EventListener when hovering a Google Map

  6. 6

    Show buttons just when the mouse is hovering the table

  7. 7

    restart image gallery when mouse is not hovering

  8. 8

    Effect when the mouse over the picture

  9. 9

    How to display a button over a picture only when hovering it?

  10. 10

    How can I make text appear when hovering a picture that has already the hovering for transform?

  11. 11

    How to show a large size of an picture when the mouse is on it?

  12. 12

    Change background color of row when hovering

  13. 13

    Change cursor when hovering a child window

  14. 14

    Change image color when hovering over li

  15. 15

    Change colors of spans when hovering parent div

  16. 16

    Prevent cursor to change when not hovering on Text - CSS

  17. 17

    Change css class when hovering html element

  18. 18

    Change background of the parent when hovering a child element

  19. 19

    Change cursor when hovering a child window

  20. 20

    Change colors of spans when hovering parent div

  21. 21

    Change image when hovering over a list of text

  22. 22

    Image shade change when hovering not working

  23. 23

    Change SVG When Hovering Menu In Bootstrap?

  24. 24

    Tooltip message when hovering on cell with mouse in wx.grid wxpython

  25. 25

    Display message when hovering over something with mouse cursor in Python

  26. 26

    Hover animation stops immediately when the mouse is no longer hovering over it?

  27. 27

    Multiple images depending on mouse location when hovering over div

  28. 28

    Display message when hovering over something with mouse cursor in Python

  29. 29

    Black squares that goes away when hovering mouse or clicking on it

HotTag

Archive