Write ejs variable in jQuery


Ask A Question





Login To post a question

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 %>"'

For more info please click herehttps://stackoverflow.com/q/56548995



Have a question or need a custom quote?
info@smartinfocare.com