D
D
Danil2014-12-23 09:34:52
JavaScript
Danil, 2014-12-23 09:34:52

How to encapsulate js file for specific module in nodejs?

In general, there is a module, let's say login.ejs + login.js.
Question: how to make login.js scope only at login.ejs level?
In other words, how to make it so that if there are 2 .button classes on the page, then the $('.button') call would only find the one in login.ejs?
PS: .ejs is an html file.
More:
If the user is not registered, then I include registration:

<% if (!registered) { %>
    <%= include login.ejs %>
<% } %>

login.ejs looks like this:
<script type="text/JavaScript" src="./javascripts/login.js"></script>
<div class="row small-4 panel">
  <label>Login
        <input class="login" type="text" placeholder="Login" />
    </label>
  <label>Password
        <input class="password" type="text" placeholder="Password" />
    </label>
  <a href="#" class="enter button small small-12">Login</a>
</div>

That is, before the HTML, I also add a link to the script with the js handler. And I need this js handler to see only this form (login.ejs), and ignore the rest of the HTML on the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2014-12-23
@Veneomin

This is in no way related to NodeJS.
Give the top div an id in the template and restrict the selector to that div in the script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question