Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. <% books.forEach(function(book){ %>
  2. <button onclick="getBookDetails(<%=book %>);" > <%=book.name %></button>
  3. <% }); %>
  4.  
  5. function getBookDetails(book){
  6. //using book object
  7. }
  8.  
  9. <% books.forEach(function(book){ %>
  10. <button onclick="getBookDetails(<%-JSON.stringify(book)%>);"><%=book.name %></button>
  11. <% }); %>
  12.  
  13. <% books.forEach(function(book){ %>
  14. <button onclick="getBookDetails('<%= JSON.stringify(book) %>')"><%= book.name %></button>
  15. <% }) %>
  16.  
  17. function getBookDetails(bookString){
  18. let book = JSON.parse(bookString)
  19. // now you can use the book object
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement