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) {
[].forEach.call(this.files, readAndPreview);
}

function readAndPreview(file) {

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

var reader = new FileReader();

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

reader.readAsDataURL(file);

}

}

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

www.codegrepper.com
www.stackoverflow.com

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")

www.codegrepper.com
www.stackoverflow.com

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 {
firstName,
lastName
};
}

//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

www.codegrepper.com
www.stackoverflow.com

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


var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
// 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);
}
});

www.codegrepper.com
www.stackoverflow.com