Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6894627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:48:23+00:00 2026-05-27T06:48:23+00:00

I have a problem with changing onmouseover and onmouseout attributes on dynamic pictures. The

  • 0

I have a problem with changing onmouseover and onmouseout attributes on dynamic pictures. The way i want it to work is whenever i put my mouse over images the images must change and when i take my mouse away it must be changed to the original picture. and whenever i select any image, that image must be changed to the image which was displayed while moving the mouse across the image. and when i select any other image the same process must take place but the previous image that was changed must be changed back to the original picture.

I have accomplished all of the above but my problem is when i select multiple pictures and put my mouse over images that were previously selected, those images do not change (onmouseover attribute does not work on them anymore).

<script language="javascript">
    function changeleft(loca){
        var od=''
        var imgs = document.getElementById("leftsec").getElementsByTagName("img"); 
        for (var i = 0, l = imgs.length; i < l; i++) {  
            od=imgs[i].id;

            if(od==loca){
                imgs[i].src="images/"+od+"_over.gif";
                imgs[i].onmouseover="";
                imgs[i].onmouseout="";
            }else{
                od = imgs[i].id;
                imgs[i].src="images/"+od+".gif";
                this.onmouseover = function (){this.src="images/"+od+"_over.gif";};
                    this.onmouseout = function (){this.src="images/"+od+".gif";};
            }

        }
    }
</script>

<div class="leftsec" id="leftsec" >
    <img id='wits' class="wits1"  src="images/wits.gif" onmouseover="this.src='images/wits_over.gif'" onmouseout="this.src='images/wits.gif'" onclick="changeleft(this.id)" /><br />

    <img id='city' class="city1" src="images/city.gif" onmouseover="this.src='images/city_over.gif'" onmouseout="this.src='images/city.gif'" onclick="changeleft(this.id)" /><br />

    <img id='organise' class="city1" src="images/organise.gif" onmouseover="this.src='images/organise_over.gif'" onmouseout="this.src='images/organise.gif'" onclick="changeleft(this.id)" /><br />

    <img id='people' class="city1" src="images/people.gif" onmouseover="this.src='images/people_over.gif'" onmouseout="this.src='images/people.gif'" onclick="changeleft(this.id)" /><br />
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:48:24+00:00Added an answer on May 27, 2026 at 6:48 am

    I would recommend to use an Ajax library (jQuery, YUI, dojo, ExtJS, …). In jQuery I would do something like:

    Edit: Extended the example with .click() ability.

    var ignoreAttrName = 'data-ignore';
    
    var imgTags = jQuery('#leftsec img'); // Select all img tags from the div with id 'leftsec'
    
    jQuery(imgTags)
    .attr(ignoreAttrName , 'false') // Supplying an ignore attribute to the img tag
    .on('click', function () {
        jQuery(imgTags).attr(ignoreAttrName, 'false'); // Resetting the data tag
        jQuery(this).attr(ignoreAttrName, 'true'); // only the current will be ignored
        // Do whatever you want on click ...
    })
    .on('mouseover', function () {
        // This will be called with the img dom node as the context
        var me = jQuery(this);
    
        if (me.attr(ignoreAttrName) === 'false') {
    
            me.attr('src', me.attr('id') + '.gif');
        }
    })
    .on('mouseout', function () {
        // This will be called when leaving the img node
        var me = jQuery(this);
    
        if (me.attr(ignoreAttrName) === 'false') {
            me.attr('src', me.attr('id') + '-over.gif');
        }
    });
    

    With a library it’s cleaner and more scalable I think and the chance that it’s working in other browsers is increased too :).

    Hope this helps you out!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem with changing onmouseover and onmouseout attributes on dynamic pictures.
I have a problem that I really need solved in any way (changing data
HI! I have a problem with changing the name of a select element. I
I have problem with return statment >.< I want to store all magazine names
I have problem with fancybox. I want to write a function that will run
I have problem with the CSS. I'm changing dynamically one div's content. The problem
Hi i got a problem with changing urls. I have files: cat-art.php (cat- category,
I'm using the jQuery datepicker from jqueryui.com and I have a problem changing the
I already tried stop(true,true), stop(true) and clearQueue(); but this doesn't work. I have problem
I have a problem with changing the color of a button (in vb.net). I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.