Home > Mobile >  How to insert EJS tag inside of apostrophes?
How to insert EJS tag inside of apostrophes?

Time:11-12

I am trying to make a GET request to a certain endpoint by clicking a button that has onClick=location.href attribute. But I can't figure out how to make EJS tag work inside of apostrophes.

<button type="button" onclick='location.href="/<%= todoList.title %>"'>delete</button>

I want to get this as an outcome:

<button type="button" onclick="location.href="/football">delete</button>

Whereas I'm getting,

<button type="button" onclick="location.href="/">delete</button>

CodePudding user response:

Try

<button type="button" onclick='location.href="/<%- todoList.title %>"'>delete</button>

use <%- %> rather than <%= %> in JS(onclick function)

Or

use link whether using button with onclick function

<a href="/<%= todoList.title %>">delete</a>

// if you use bootstrap as framework
<a href="/<%= todoList.title %>" class="btn">delete</a>

  • Related