How can I conditionally format my HTML table?

General Tech Bugs & Fixes 2 years ago

0 4 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (4)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0
 class='detail-hide'> Class='result-name '>pmu: COMMITTED_PKT_BSB
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1655.0
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1836.0
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1655.0
 Class='metric' title='Test gave a performance metric.' lastPassTag=''>1836.0

I have a HTML table like above I'm trying to do conditional formatting based on the formula applied on the numbers there I tried this:

var tb = document.getElementByClass('metric')

I could not get those values Any modifications or suggestions are appreciated Thank you
profilepic.png
manpreet 2 years ago

The only problem with your code is you are using wrong js context to search for class using js.

document.getElementByClass('metric')


as classes can be more then 1 so the context to select class is having elements instead of element like below

document.getElementsByClass('metric')

hope this will solve your query.

 


0 views   0 shares

profilepic.png
manpreet 2 years ago

The method is wrong - you want to use document.getElementsByClassName:

var tb = document.getElementByClass("metric");

You could also use querySelectorAll to only get td elements with the class metric:

var tb = document.querySelectorAll("td.metric");

 

 

 


0 views   0 shares

profilepic.png
manpreet 2 years ago

There are two tag/problems">problems :

tag/1">1) You miss first  and last  and also must wrap your trs in table tag .

2) Change :

document.getElementByClass('metric') ;    

To:

document.getElementsByClassName('metric') ;

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.