Slasher Slasher - 5 months ago 23
jQuery Question

Format string into HTML <li> elements

How could I split string or get invidual words out of string. I'm trying get output like this whit

<li></li>
elements:

-Ryan Gosling
-Emma Stone
-Amiée Conn
-Terry Walters


But it keeps displaying like this in single row: Ryan Gosling, Emma Stone, Amiée Conn, Terry Walters,


Fiddle JS code: https://jsfiddle.net/ysch9hfg/5/


$(document).ready(function() {
$("button").click(function () {
$("ul.list-group.list-group-flush").append('<li class="list-group-item">' + (filmi.Movies[0].Actors) + '</li>')
});
});

Answer Source

https://jsfiddle.net/9bwwuobw/

$("ul.list-group.list-group-flush").append(
    '<li class="list-group-item">' + 
    (filmi.Movies[0].Actors.split(', ').join(
         '</li><li class="list-group-item">'
     ) + '</li>'
 )});