user2829448 user2829448 - 5 months ago 64x
Javascript Question

Appending EJS partial with jQuery

I'm trying to use JQuery to append an EJS partial. What I want to do is to implement infinite scrolling in a table - I am using EJS to render the table's rows as partials and within each partial using more EJS to display the variables passed into the view from Express.


<% include row.html %>


<% users.forEach(function(user){ %>
<td><%= %></td>
...and so on
<% }) %>


$('tbody').append('<%- include row.html %>')

The issue I'm having now is that I can't get the last <% include row.html %> to work in the jQuery. I have debugged this and isolated the issue to this line of code. What can I do to make this work?



Make sure to escape your HTML, meaning if it contains a single quote, it won't work.

$('tbody').append('<p>Johny's HTML AIN'T werkin'!</p>');

should be

$('tbody').append('<p>Johny\'s HTML IS werkin\'!</p>');