Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  173] [ 1]  / answers: 1 / hits: 17732  / 13 Years ago, mon, february 27, 2012, 12:00:00

I want to create image object when user selecting a file from html page.





How can i create image object for dynamic images. Can anybody share me the sample snippet .



Thanks in advance


More From » javascript

 Answers
13

Basically:




  • You can create an img element like any other element: createElement. (There's also new Image() which is pretty much the same thing, just a legacy mechanism.)


  • You can set its source by setting the src property, which can be a file:// URL the user supplies...


  • ...or you can let them choose via an input type=file element if their browser supports using the File API; see my answer to this other question for getting access to image data that way.


  • You can put the img element in the document by appending it to whatever other element you want to append it to, via appendChild or related methods.


  • You can find an existing element using getElementById, getElementsByTagName, etc., or (on most browsers but not all) querySelector / querySelectorAll.




In addition the various specifications linked inline above, you may also find the new work-in-progress HTML5 specification useful.


[#87186] Saturday, February 25, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianod

Total Points: 667
Total Questions: 106
Total Answers: 92

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
lucianod questions
;