JavaScript element Creation Doubt | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

JavaScript element Creation Doubt

To create a img on ECMA we use im=new Image() right,???? But the element actually "img" and not "Image"... So is this applicable for all elements like using L=new List() for creating an "li" element...

1st Jun 2020, 10:24 AM
sid - avatar
2 Answers
+ 1
I don't think you can do that. Use document.createElement()
1st Jun 2020, 10:42 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
sid "The HTMLImageElement interface represents an HTML <img> element, providing the properties and methods used to manipulate image elements." Image() is a constructor of the HTMLImageElement interface and is from the browser, not ECMA script. While there is an HTMLLIElement interface it does not provide a constructor, MDN provides a list of Web APIs and interfaces, you should take a look.
1st Jun 2020, 12:03 PM
ODLNT - avatar