Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Why does the 'onmouseover' keyword change another targets in HTML?

I run it on Chrome

My problem - After the mouse touches all the images, even if onmouseout from one image, all images change at the same time

I do not understand why this is

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <img src="https://i.stack.imgur.com/iYL3x.gif" onmouseover="this.src='https://i.stack.imgur.com/ht3Jw.gif'" onmouseout="this.src='https://i.stack.imgur.com/lmBrB.gif'">
  <img src="https://i.stack.imgur.com/iYL3x.gif" onmouseover="this.src='https://i.stack.imgur.com/ht3Jw.gif'" onmouseout="this.src='https://i.stack.imgur.com/lmBrB.gif'">

</body>
</html>

Image Source info

artist:Sevarihk

Original:https://opengameart.org/content/animated-bamboo-door-sprite

[dor_1.gif][1]
[door_1_close.gif][2]
[door_1_open.gif][3]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is because both <img> represent the same and only internal gif image. When you do set the <img>'s src to that URL again, the gif animation is reloaded, as per specs. But it is reloaded for all instances of this image.
You can avoid that by tricking the browser in thinking both images are separate, e.g by appending a query-param to the URL:

(Notice the ?A and ?B I added at the end of the URL in the mouseout event handlers).

<img src="https://i.stack.imgur.com/iYL3x.gif" onmouseover="this.src='https://i.stack.imgur.com/ht3Jw.gif'" onmouseout="this.src='https://i.stack.imgur.com/lmBrB.gif?A'">
<img src="https://i.stack.imgur.com/iYL3x.gif" onmouseover="this.src='https://i.stack.imgur.com/ht3Jw.gif'" onmouseout="this.src='https://i.stack.imgur.com/lmBrB.gif?B'">

But this means the image is actually loaded twice...

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!