Guest User

Untitled

a guest
Dec 11th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. "use strict";
  2. const populate = function(target, element){
  3. //get an array containing elements from the document with the class specified
  4. let spans = document.getElementsByClassName(target);
  5.  
  6. /*for each element, find the pre element inside. divide into individual strings
  7. on linebreaks and append each as a element of the specified type to the span*/
  8. for (let i = 0; i < spans.length; i++){
  9.  
  10. let text = spans[i].getElementsByTagName("pre")[0].innerHTML;
  11. let paras = text.trim().split(/[\r\n]+/);
  12.  
  13. for (let j = 0; j < paras.length; j++){
  14. let para = document.createElement(element);
  15. para.innerHTML = paras[j];
  16. spans[i].appendChild(para);
  17. };
  18. };
  19. };
Add Comment
Please, Sign In to add comment