Solved

creating an image element in FireFox

Posted on 2007-12-03
2
502 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Blog Template 2 37
jQuery AJAX Redirects Without Response/Error 10 46
Wrapper for APPs 9 37
Why my select dropdown does not work? 8 27
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

896 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

17 Experts available now in Live!

Get 1:1 Help Now