Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
EJS string variable returns element with id

I am trying to access a simple string variable using EJS. But it returns me an element with same id instead of the string itself.

app.get("/favorites", function(req, res) {
    res.render("index", {active: "favorites", datas: datas});
});

This is the node.js server side

<script>
    if (<%= active %> === "favorites"){
        $("#favorites").attr("src","favorites-active.jpg");
    } else if (<%= active %> === "communities") {
        $("#favorites").attr("src","communities-active.jpg");
    }
    console.log(<%= active %>);
</script>

This is the script I run inside my EJS file, as the result I get the element with id 'favorites'

<div class="sideNav-Item" href="/favorites"onclick="ChangePage('favorites');">

I want to get "favorites" string value only? Please help.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda