Skip to content

Instantly share code, notes, and snippets.

@ralfting
Created August 27, 2019 19:46
Show Gist options
  • Select an option

  • Save ralfting/5843914248b91aa074e6e6ed9bde5af5 to your computer and use it in GitHub Desktop.

Select an option

Save ralfting/5843914248b91aa074e6e6ed9bde5af5 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
'use strict';
const $textBuildList = $('.build-list-js > p');
const templateLi = text => `<li>${text}</li>`;
const stringToArray = paragraph => paragraph.split('\n');
$textBuildList.each(function textToList(index, text) {
const arrText = stringToArray(text.innerText);
let listHtml = "";
arrText.forEach(function appendInTheList(text) {
if(text === "") return;
const textWithTemplate = templateLi(text);
listHtml = listHtml.concat(textWithTemplate);
});
$textBuildList.innerHTML = '';
$textBuildList[index].innerHTML = listHtml;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment