Jump to content

adding image using js


divinedesigns1
 Share

Recommended Posts

how can i go about adding an image in javascript code, if im using innerhtml to display my html text?

Link to comment
Share on other sites

With innerHTML, you would just put the image's HTML:

var filename = "image.jpg";element.innerHTML = "<img src='" + filename + "'>";

If you want a different method

var img = new Image();img.src = "image.jpg";element.appendChild(img);
Link to comment
Share on other sites

 

With innerHTML, you would just put the image's HTML:

var filename = "image.jpg";element.innerHTML = "<img src='" + filename + "'>";

If you want a different method

var img = new Image();img.src = "image.jpg";element.appendChild(img);

thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...