Необходимо реализовать вывод цитаты из массива. Имеется такой блок <div class="motivation"></div>. Как можно вывести рандомную заготовленную цитату из массива в блок motivation?
var myArray = ['Цитата 1', 'Цитата 2', 'Цитата 3', 'Цитата 4', 'Цитата 5'];
var rand = Math.floor(Math.random() * myArray.length);
var concat = myArray[rand];
function random() {
var text = document.getElementsByClassName('motivation');
text.write = (concat);
}
<div class="motivation"></div>
var text = document.getElementsByClassName('motivation'); // Выбрали элементы с классом
// Проходим по каждому элементу
Array.prototype.forEach.call(text, function(elem) {
var myArray = ['Цитата 1', 'Цитата 2', 'Цитата 3', 'Цитата 4', 'Цитата 5'];
var rand = Math.floor(Math.random() * myArray.length);
var concat = myArray[rand];
elem.innerHTML = concat; // Запись в блок
});
<div class="motivation"></div>
<div class="motivation"></div>
<div class="motivation"></div>
var myArray = ['Цитата 1', 'Цитата 2', 'Цитата 3', 'Цитата 4', 'Цитата 5'];
var rand = Math.floor(Math.random() * myArray.length);
var concat = myArray[rand];
$('.motivation').text(concat);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="motivation"></div>
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости