What is the best JavaScript code to create an img element?

JavascriptObject Oriented ProgrammingFront End Technology

Try any of the following for the width of the image you want to create −

myImg.setAttribute('width', '5px');

Or

myImg.width = '5';

Or

myImg.style.width = '5px';

You can also try the following code to add the width and height to the background image −

var myImg = new Image(5,5);
myImg.src = 'http://www.example.com';
raja
Published on 27-Feb-2018 11:09:23
Advertisements