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 8365025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:56+00:00 2026-06-09T12:33:56+00:00

I’m using JavaScript to create and remove elements from a web page. I’ve got

  • 0

I’m using JavaScript to create and remove elements from a web page. I’ve got it working in every browser except Firefox. In Firefox it will create the element, remove the element, re-create the element but after re-creating the element it returns a “not found” type error saying the element doesn’t exist and it gets stuck predominantly on the screen at that point.

This creates the Image:

function createMOImage( objId )
{
    var img = document.createElement('img');
    var leftOffset = document.getElementById( objId ).offsetLeft;

    img.src = 'images/pre-butt-mo.png';
    img.style.position = 'absolute';
    img.style.left = leftOffset + "px";
    img.style.opacity = '0.2';
    img.style.zindex = '9';
    img.id = 'temp';
    img.onmouseout = function () { moff( objId ); };

    return img;
}

As you can see, the image created is given a mouse out event calling this function:

function moff( objId )
{
    var container = document.getElementById( 'container' );
    var temp = document.getElementById( 'temp' );

    removeMOImage( );
    changeButt( objId );

    return;
}

The change function works perfectly fine but it’s not getting called because the JavaScript is being terminated in the removeMOImage() function:

function removeMOImage(  )
{
    if ( img = document.getElementById('temp') )
    {
        img.parentNode.removeChild( temp );
    } else {
        return;
    }
}

The removeChild function is returning the not found despite the fact the element was successfully recreated in the create function.

I tested in IE Chrome Opera and Firefox and the only one having issues is Firefox. There were a few other FF specific issues I had to overcome, most of which were solved from other stack overflow threads; however, I could not find a solution to this issue.

This is the full JavaScript c&p from the source:

function mon( objId )
{

    var container = document.getElementById( 'container' );
    var img = createMOImage( objId );

    container.appendChild( img );
    changeButt( objId );

    return;
}

function moff( objId )
{
    var container = document.getElementById( 'container' );
    var temp = document.getElementById( 'temp' );

    removeMOImage( );
    changeButt( objId );

    return;
}

function createMOImage( objId )
{
    var img = document.createElement('img');
    var leftOffset = document.getElementById( objId ).offsetLeft;

    img.src = 'images/pre-butt-mo.png'; // change image names to match button ID's
    img.style.position = 'absolute';
    img.style.left = leftOffset + "px";
    img.style.opacity = '0.2';
    img.style.zindex = '9';
    img.id = 'temp';
    img.onmouseout = function () { moff( objId ); };

    return img;
}

function removeMOImage(  )
{

    // find cross browser approach. General consensus is to use remove child from the parent div reference but there are alot of issues.
    // Also have issue with mouse moving over the element causing the element to be deleted even though the mouse never actually leaves the element.

    // Best Hypothesized solution - move the mouseout event to the MO image
    // Confirmed solution for Chrome and IE but FF will only delete the image after the first MOut, after recreating the element it stays perminantly
    if ( img = document.getElementById('temp') )
    {
        img.parentNode.removeChild( temp );
    } else {
        return;
    }

}

function changeButt( objId )
{
    var img = document.getElementById( objId );
    var imginv = document.getElementById( objId + "inv" );
    var temp = document.getElementById( 'temp' );

    if ( temp != null )
    {
        img.src = "images/blank-butt.png";
        imginv.src = "images/blank-butt-inv.png";
        return;
    } else {
        img.src = "images/" + objId + ".png";
        imginv.src = "images/" + objId + "inv.png";
        return;
    }    
}

The purpose is to create an image over another image and to delete the image when the mouse is removed from the newly created image ( which is larger than the original image ). It would be VERY much appreciated if this can be solved. I really don’t want to use flash.

Another issue is that the opacity attribute doesn’t seem to work in IE. Ill work on that solution solo unless anyone here has any ideas. And if possible, would some one mind testing on safari? don’t have access to a Mac.

*I apologize for the stupid notes, they were meant to help me keep track when I walked away from computer.

[edit] I fixed the opacity issue.
[edit] Resolved the issue by creating an extra variable.

  • 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-06-09T12:33:57+00:00Added an answer on June 9, 2026 at 12:33 pm

    This is a scoping issue. You define the temp variable in one function and try to refer to it in another function.

    function moff( objId ) {
        var container = document.getElementById( 'container' );
    
    
        removeMOImage( );
        changeButt( objId );
    }
    
    
    function removeMOImage(  ) {
        var temp = document.getElementById( 'temp' );
    
        if ( temp ) {
            temp.parentNode.removeChild( temp );
        }
    }
    

    You also don’t need the return statements at the end. If you don’t quit early or return a value, you are imitating what the interpreter does for you anyway.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.