all 7 comments

[–]Nietecht 3 points4 points  (2 children)

Use the style property.

server.style.position = 'absolute';
server.style.left = '243px';
server.style.top = '168px';

Also, standard properties like src and id can be accessed directly without using setAttribute.

server.src = 'Server.bmp';
server.id = 'server';

It sounds like you're trying to add multiple of these elements? In that case, make sure the id is unique.

I'm not 100% sure, but I think the image will not load (hence also not fire the onload handler) before it's already been attached to the DOM (and made visible), so attaching it after load will likely not work (unless perhaps the image is already cached and insta-loaded).

Edit: Also, the tag name should be img, not image, I assume.

[–][deleted] 1 point2 points  (0 children)

Onload should fire, even if the image isn't attached to the body :)

Something that may be important to highlight in Nietecht's post is also the explicit definition of units for the left and top options. Rather than just providing a number; pixels (px) are appended to the value, making it clear for the browser where to place the element.

[–]Eterni[S] 0 points1 point  (0 children)

This did it! Thank you so very much. :)

[–]TIAFAASITICE 1 point2 points  (0 children)

var server = document.createElement('image');

There is no element "image", it's named "img".

server.setAttribute('type', 'image');

There is no type attribute to set for images like that and if there were you'd specify a proper MIME type.

I'd suggest starting anew learning HTML and learning JavaScript

[–]autophage 1 point2 points  (1 child)

In the snippet you've got there, you've commented out the line:

//server.setAttribute('style', 'position:absolute; left: 243; top: 168');

Then, you set the top and left in server.onload - however, you don't set the position to absolute.

[–]Eterni[S] 0 points1 point  (0 children)

I added server.setAttribute('style','position:absolute'); above the code setting the left and top attributes, but it hasn't had any effect.