Note that there are some explanatory texts on larger screens.

plurals
  1. POmove the mouse pointer over an image
    primarykey
    data
    text
    <p>I have 4 images in an HTML page: 1.png, 2.png, 3.png and 4.png. When the user moves the mouse pointer over to 1.png, 2.png should replace 4.png. Similarly, if the mouse pointer goes to 2.png, 3.png should be replaced with 1.png.</p> <p>Here's my code:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;script type="text/javascript"&gt; function image1_mouseover() { var img2 = document.getElementById('img2'); var img4 = document.getElementById('img4'); img2.setAttribute('src','exercice1/4.png'); img2.setAttribute('id','img4'); img4.setAttribute('src','exercice1/2.png'); img4.setAttribute('id','img2'); } function image2_mouseover() { var img1 = document.getElementById('img1'); var img3 = document.getElementById('img3'); img1.setAttribute('src','exercice1/3.png'); img1.setAttribute('id','img3'); img3.setAttribute('src','exercice1/1.png'); img3.setAttribute('id','img1'); } function image3_click() { } &lt;/script&gt; &lt;style type="text/css"&gt; table { margin-left:auto; margin-right:auto; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;table class="centrer"&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="exercice1/1.png" alt="Image 1" id="img1" onmouseover="image1_mouseover()"&gt;&lt;/td&gt; &lt;td&gt;&lt;img src="exercice1/2.png" alt="Image 2" id="img2" onmouseover="image2_mouseover()"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="exercice1/3.png" alt="Image 3" id="img3"&gt;&lt;/td&gt; &lt;td&gt;&lt;img src="exercice1/4.png" alt="Image 4" id="img4"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It works at first when I move the mouse to 1.png and 2.png replaces 4.png. But then when I move the mouse to 2.png, 1.png doesn't replace 3.png, instead I had to move the mouse over 4.png for that to happen.</p> <p>What's wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload