I am very unexperienced in Javascript/Jquery therefore I use the JavaScript Load Image plugin to handle the front end of my image upload process.
I would like to :
At the moment the thumbnails are appended to the end.
system 'clear'
<!-- FILE INPUT -->
<p><input type="file" name="images[]" id="upload-post-images" multiple></p>
<!-- THUMBNAILS -->
<div id="result" class="result">
<p>Here the thumbnails should be displayed.</p>
</div>
I would be very thankful for any kind of help!!
答案 0 :(得分:1)
It's appending to the end, because that's exactly what you're telling it to do here:
toString
That's appending the image to the body - that is, adding it to the end.
What you want to be doing is appending it to your target div. You can find the div with the document.querySelector() function, and then append the image to that:
document.body.appendChild(img);
Where '#' means 'has an id of', and '.' means 'has a class of', for instance. If you were running this code with jQuery loaded, you could use the $() or jQuery() function instead, but your code is outside of the document.querySelector('#result').appendChild(img)
block, so it will run before jQuery has loaded.
The $(function(){})
is just shorthand for $(function(){})
, which runs the enclosed function when the document has loaded (and thus loaded jQuery).