I am appending some html to a div using jQuery:
public/js/writeInputs.js
$("#myDiv").append("<input type='search' value='<%= filters.title %>' name='filters[title]' class='form-control'>")
In this case filters is an object that I'm passing from my node express backend, the value of which I want to display in my input. However, the above renders the ejs variable as the string literal:
<%= filters.title %>
If I hardcode this value into the html it works as expected:
views/partials/inputs.ejs
<input type="search" name="filters[title]" value="<%= filters.title %>" class="form-control">
How can I write an ejs variable in jQuery?
I've tried these approaches in my append, but none work:
value="<%= filters.title %>"
value=${<%= filters.title %>}
value='"<%= filters.title %>"'
from Write ejs variable in jQuery
No comments:
Post a Comment