2

Please mind the environment of this Application. I'm using

  1. Windows
  2. NPM ,Express
  3. MySQL

This is the code in ejs template. example.ejs

<% if (message) { %>
                <p class="alert " id="errorMessage">
                    <%= message %>
                </p>
            <% } %>

I want to add class to p.

This is what I am doing but didn't work.

messages = "Password Successfully Changed";
jQuery('#errorMessage').addClass('successMessage');
res.render('profile',{page_title:"My Profile",data:rows,message: messages});

1 Answer 1

3

I got the answer.

var messageData = {
  message : "Password Successfully Changed",
  class : "successMessage"
};
res.render('profile',{page_title:"My Profile",data:rows,message: messageData });

then on template side.

<% if (globalMessage) { %>
    <p class="alert <%= globalMessage.class %>" id="errorMessage">
       <%= globalMessage.message %>
    </p>
<% } %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.