문제

I have these 3 lines of code in an external javascript file

function init(){
document.getElementById("upcoming_event").getElementsByTagName("img")[0].src = "images/fastnet_2013_poster.jpg";
    document.getElementById("club_championship").getElementsByTagName("img")[0].src = "images/club_championship.png";
    document.getElementById("setMembership").getElementsByTagName("img")[0].src = "images/join_our_club.png";
}

document.addEventListener( "DOMContentLoaded" , init , false);

This code works perfectly on this site which i used just to develop a little bit of it with 000webhosting.

But I have now moved my hosting to hosting24 to complete the development of the site. When i load the site through the new host(hosting24) the images are not getting loaded.

I have taken these 3 line of code out and tried them in an <body onload="init()"> but this dose not load the images either.

I know that both methods above are being called as i have got them to display a window.alert("Display").

Is there another way of doing this?

(document.getElementById("upcoming_event").getElementsByTagName("img")[0].src = "images/fastnet_2013_poster.jpg";) that i could try and use? Or solve my problem.

도움이 되었습니까?

해결책

Changing servers should not effect javascript code at all. Only thing that comes to mind is that the URL's for the images sources isn't correct anymore, because of the move.

다른 팁

First you can use jQuery to help you do this in a simpler way like:

$('#upcoming_event').find('img')[0].src = "url";

or

$('#imgid').attr('src', 'xpto.jpg');

Secound, the code seems to work... I think the problem may be in the urls of the IMGs. Check if the images are in the correct folder or if the path is right.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top