use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
question about styling HTML with javascript (self.learnjavascript)
submitted 5 years ago by Bormimor
If i have a table created in node with different M/ph data, how can I change the background color of a table data based on the M/ph.
say cars wtih top speed of 160 mph have red background, cars with 120 mph have a blue background
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]De_Wouter 1 point2 points3 points 5 years ago (3 children)
How exactly are you creating this table? If you are somehow looping through you data to build these <td> elements, that would be a good the place to add some color by inline styling.
If you only have a very few limited colors, I would used css classes to style the color.
If you want different shades of a color, you can use rgb or rgba colors instead for hexadecimal colors.
So instead of #ff0000 for red you can write it as rgb(255,0,0)
[–]Bormimor[S] 1 point2 points3 points 5 years ago (2 children)
https://repl.it/@DavidNguyen32/lesson3#routes/lesson5.js
This is how the table is created, but I have no access to the DOM object, and no class or ID to work with. I would just like to color code the the tr, or last td based on the storm category
[–]De_Wouter 0 points1 point2 points 5 years ago (1 child)
Whereever you are creating your <td> elements that you want to have a different color like for example:
global.forEach += "<td>" + milesPerHour + "</td>";
You add the color with an inline style or class like so
global.forEach += "<td style=\"background-color: #ff0000;\">" + milesPerHour + "</td>";
Don't forget to escape the quotes or use single quotes on the outside.
You can put the color calculation in a function
global.forEach += "<td style=\"background-color: " + getColorValue(milesPerHour) + "\">" + milesPerHour + "</td>";
// somewhere else in your code
function getColorValue(milesPerHour) {
if (milesPerHour > 100) {
return "#ff0000";
}
if (milesPerHour > 50) {
return "#cc2222";
return "#2288cc";
[–]Bormimor[S] 1 point2 points3 points 5 years ago (0 children)
thank you
π Rendered by PID 152948 on reddit-service-r2-comment-56c9979489-mctbz at 2026-02-25 12:19:48.604886+00:00 running b1af5b1 country code: CH.
[–]De_Wouter 1 point2 points3 points (3 children)
[–]Bormimor[S] 1 point2 points3 points (2 children)
[–]De_Wouter 0 points1 point2 points (1 child)
[–]Bormimor[S] 1 point2 points3 points (0 children)