Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to assign javascript variable to html element inside javascript

I'm trying to insert javascript variable value in html element inside javascript.. But it's not working properly.. following are my code..

 window.onload = function() {
    var image=document.getElementById('img').value;
        var img = '<div id="pic"><img src="image" width="200" height="108" /><p></p></div>';
      }

This is the function. Here i'm getting image in variable image.. i'm trying to assign this image to in one div id pic.. there i'm assigning src="image" which i got in var image.. But its not working..

like image 837
Dhinesh.B Avatar asked Oct 31 '25 15:10

Dhinesh.B


1 Answers

You need to insert the value into the string:

var img = '<div id="pic"><img src="' + image + '" width="200" height="108" /><p></p></div>';
like image 178
Blender Avatar answered Nov 03 '25 06:11

Blender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!