Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Estoy tratando de ejecutar un código jQuery para cambiar el color h1 en función de si es un día de semana o un fin de semana

Estoy tratando de ejecutar un código jQuery para cambiar el color h1 en función de si es un día de semana o un fin de semana. El error que recibo es 'ReferenceError: $ is not added', ¿alguien puede ayudarme? app.js se encuentra en parentfolder/app.js mientras quelists.ejs se encuentra en parentfolder/views/lists.ejs . document.queryselector tampoco funciona

aplicación.js

 const express = require("express"); const bodyPareser = require("body-parser"); const app = express(); app.use(bodyPareser.urlencoded({extended : true})); app.set("view engine", "ejs"); app.get("/", function(req, res) { var date = new Date(); var currentDay = date.getDay(); var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; if (currentDay === 0 || currentDay === 6) { $(h1).style.color = "red"; } else { $(h1).style.color = "blue"; } res.render("lists", {today : days[currentDay]}); res.sendFile(__dirname + "/views/lists.ejs"); }); app.listen("3000", function() { console.log("Server started in 3000"); });

listas.ejs

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1>Today is <%= today %></h1> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="app.js"></script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

cuando usa Node, está ejecutando el lado del servidor (para usar una biblioteca, necesita solicitarla), tampoco puede usar los selectores del lado del cliente porque no existen

dentro app.js

 app.get("/", function(req, res, next) { const date = new Date(); const currentDay = date.getDay(); const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; let day_color if (currentDay === 0 || currentDay === 6) { day_color = "red"; } else { day_color = "blue"; } res.render("lists", {today : days[currentDay],color:day_color}, (err,html) => { if(err){ console.log(err) return next(err) } res.send(html) }) });

dentro list.ejs

 <h1 <%= `style=color:${color}`%> >Today is <%= today %></h1>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!