1

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.

5
  • Your code looks fine, assuming all the variables reference valid elements. Is there an issue with the code? Commented Jul 20, 2017 at 8:39
  • What is the image src? Your variable for the image is undeclared. Commented Jul 20, 2017 at 8:39
  • I'm declaring the image path with the variable(var image1="image_path") @gwalshington Commented Jul 20, 2017 at 8:41
  • I'm not able to display the image inside the html. should we give an absolute path or a relative path, if so how should we actually code for that.@RoryMcCrossan Commented Jul 20, 2017 at 8:42
  • Okay - think you should look at your src path. Try replacing that with var image1="http://r.ddmcdn.com/w_606/s_f/o_1/cx_0/cy_15/cw_606/ch_404/APL/uploads/2014/06/10-kitten-cuteness-1.jpg" and it should work fine Commented Jul 20, 2017 at 8:45

2 Answers 2

1

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>

Sign up to request clarification or add additional context in comments.

Comments

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

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

Comments

Your Answer

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