Solved

creating an image element in FireFox

Posted on 2007-12-03
2
499 Views
Last Modified: 2012-05-05
Hi,

I have written some simple code that creates an image element, assigns the src and appends it to an existing element. Now this works fine in IE but not firefox.  Please coul some shed some light on this and a possible solution.

Below is my code:

Andrew
function AddImage(imageNumber, imageUrl)

{

    var o = document.getElementById("Image"+imageNumber);

    o.parentNode.className = "HasPhoto";

    var imageNode = document.createElement("image");

    imageNode.src = imageUrl; 

    o.appendChild(imageNode); //this only works in IE for some reason

    if(imageNumber!=3)

    {

        var nextObj= imageNumber+=1;

        document.getElementById("Image"+nextObj).parentNode.className = "FirstPhoto";

    }

}

Open in new window

0
Comment
Question by:REA_ANDREW
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 20396600
Try this:

function AddImage(imageNumber, imageUrl)
{
    var o = document.getElementById("Image"+imageNumber);
    o.parentNode.className = "HasPhoto";
    var imageNode = document.createElement("img");
    imageNode.src = imageUrl;
    o.appendChild(imageNode); //this only works in IE for some reason
    if(imageNumber!=3)
    {
        var nextObj= imageNumber+=1;
        document.getElementById("Image"+nextObj).parentNode.className = "FirstPhoto";
    }
}
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 20397217
lol ofcourse!!!!! nice one for that, I have had a total lapse in brain activity!!! thanks again

Andrew
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now