question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to work with DOM.

See original GitHub issue

Is it possible to using something like this?

<% var bt = document.getElementById("page2");
        bt.addEventListener('click',function(){
          alert("123")}); %>

thanks for reply.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
RyanZimcommented, Mar 25, 2016

This isn’t how EJS works. To use it on the client side, you would do something like:

var name="John Doe";
var str="Hello <%= name %>!";
var result=ejs.render(str);
document.write(result);
// => Hello John Doe!

Of course you would use something other than document.write.

Includes are not natively supported on the client side.

Warning: Doing complex EJS logic on the client side can get very messy since JS support for multi-line strings isn’t very good. (This doesn’t apply if you are getting your EJS templates from an external file via AJAX.)

0reactions
EasonWang01commented, Mar 28, 2016

ok,I found that I can using html = new EJS({url: ‘/template.ejs’}).render(data)

on client side

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to the DOM - Web APIs | MDN
The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document ......
Read more >
The DOM Explained for Beginners - freeCodeCamp
The DOM is a top down representation of all the elements that make up a web page. It's the interface through which your...
Read more >
JavaScript HTML DOM - W3Schools
The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents: "The W3C Document Object Model...
Read more >
Understanding the DOM — Document Object Model
The Document Object Model, usually referred to as the DOM, is an essential part of making websites interactive. It is an interface that...
Read more >
What is a DOM element in JavaScript? How does it work?
Document Object Model or DOM is an interface that defines how the browser reads your XML or HTML document. JavaScript is allowed to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found