How do you run JQuery code inside of an EJS forEach loop? I am trying to read from a mongoDB document taken in through Node.js with Express as the engine. With each item, I want to create an li
item with the items name as the list-item text. Currently, this is what I have:
<% data[0].user_projects.forEach(function(project) { %>
$('#projUL').append('<li><%= project.project_name %></li>');
<% }); %>
When I go to the page, however, it throws no errors; but inside the source code it shows the following script, but it never renders to the page:
<script>
$('#projUL').append('<li>Express Project 1</li>');
</script>
If I remove the script tags, it just inserts plain text of the same code. So, I cannot figure out how to get jQuery code inside of an EJS forEach loop. It never renders the results, no matter what I do. It only seems to take in plain text.
`), but I mean you shouldn't. I can't see any reason not to use plain html here.
– Bergi Mar 29 '15 at 22:24ul
instantiated later in the page, but it refuses to run the jquery. – boom_box Mar 29 '15 at 22:31