user8265273
user8265273

Reputation:

How to display image using javascript dynamically

I have a javascript code and i want to insert an image inside the dynamically created html page. Please correct me if i'm going wrong with the code. the code runs something like this:

var html = [
  '<div class="uicomponent-panel-controls-container");">',
  '<img src=' + image1 + '>',
  '</div>'
].join('\n');

_dockPanel.container.append(html);

Thanks in advance.

Upvotes: 1

Views: 5379

Answers (2)

chen lin
chen lin

Reputation: 21

var html = [...].join('');

html rendering dom does not need to be separated by '\n'

Upvotes: 1

hallleron
hallleron

Reputation: 1992

You have a typo here: ...container");">'

Here is the working (for demo purpose slightly modified) fiddle:

var image1 = 'https://image.flaticon.com/teams/slug/freepik.jpg';
var html = [
  '<div class="uicomponent-panel-controls-container">',
  '<img src=' + image1 + '>',
  '</div>'
].join('\n');

document.getElementById("dock").innerHTML = html;
<div id="dock"></div>

Upvotes: 1

Related Questions