0

So I am trying to insert images into <marquee> from a js file. This is what my js file looks like?

function buildList() {
    var data= ['logo1.png', 'logo2.png', 'logo3.png'];

    //var data2 = [{2:"hello"},{3:"world"},{6:"PSI"},{4:"ali"},{7:"buck"},{1:"hello"},{8:"albert"},{5:"wow"}];
    var marquee = document.getElementsByTagName('marquee');

    for(var i in data) {
        var img = new Image();
        img.onload = function() {

            //var newListItem = ' ' + data[i] +  ' there should be an img coming in from an array here';

            return img;
        };

        img.src = data[i];
        marquee[0].innerHTML  +=  img ;
        //http:www.quackit.com/pix/milford_sound/milford_sound_t.jpg"alt="Milford Sound in New Zealand' "Width=80 Height=80" ' + img;
    }
}

However when I look at the developer console in chrome, I get no error messeges by inside the marquee it is giving me [object HTML ImageElement]... What am i doing wrong?

1

1 Answer 1

2

Use appendChild instead of setting the innerHTML

marquee[0].appendChild(img);
Sign up to request clarification or add additional context in comments.

4 Comments

the thing is that this method does not allow for any space and text after the image goes in. So after the img is inserted, I also need to insert some text from another array.
@AliAslam,ok, why not create a new div or p element and use appendChild?
for text use marquee[0].innerHTML += '<div>text</div>';
I solved it by creating a TextNode inside my for loop and then doing appendChild(textnode) after appendChild(img).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.