how to show multiple image preview in jquery

<input id="file-input" type="file" multiple>
<div id="preview"></div>

function previewImages() {

var preview = document.querySelector('#preview');

if (this.files) {
[], readAndPreview);

function readAndPreview(file) {

// Make sure `` matches our extensions criteria
if (!/.(jpe?g|png|gif)$/i.test( {
return alert( + " is not an image");
} // else...

var reader = new FileReader();

reader.addEventListener("load", function() {
var image = new Image();
image.height = 100;
image.title =;
image.src = this.result;




document.querySelector('#file-input').addEventListener("change", previewImages);

how to select multiple jquery element at once

// To select multiple html element at once using jquery, follow the syntax below
$("tagName1, tagName2, tageName3")
// The above code will select "tagName1", "tagName2", tagName3

// To select multiple element using "class name" follow the syntax below
$(".className1, .className2, .className3, .className4")

// To select multiple element using "id name" follow the syntax below
$("#idName1, #idName2")

how to return multiple values from a function javascript

var values = getValues();
var first = values[0];
var second = values[1];

function getNames() {
// get names from the database or API
let firstName = 'John',
lastName = 'Doe';

// return values
return {

//function that returns multiple values
function getTopTwoColors() {
return ["blue", "pink"];
var topTwoColors=getTopTwoColors();
var firstValue=topTwoColors[0]; //get first return value
var secondValue=topTwoColors[1]; //get second return value

how to push multiple data to different parents in a single request in firebase

var ref = new Firebase("https://<YOUR-FIREBASE-APP>");
// Generate a new push ID for the new post
var newPostRef = ref.child("posts").push();
var newPostKey = newPostRef.key();
// Create the data we want to update
var updatedUserData = {};
updatedUserData["user/posts/" + newPostKey] = true;
updatedUserData["posts/" + newPostKey] = {
title: "New Post",
content: "Here is my new post!"
// Do a deep-path update
ref.update(updatedUserData, function(error) {
if (error) {
console.log("Error updating data:", error);