<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
</tr><tr class='detail-hide'><td Class='result-name '>pmu: COMMITTED_PKT_BSB</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1655.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1836.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1655.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1836.0</td>
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
Conditional rendering of HTML is not a new concept, but it cannot be done using HTML exclusively. You would need to use either client side scripting or server side code to provide the conditional logic that would render your HTML accordingly.
Select the desired cells for the conditional formatting rule. From the Home tab, click the Conditional Formatting command. A drop-down menu will appear. Hover the mouse over the desired conditional formatting type, then select the desired rule from the menu that appears.
To create table in HTML, use the <table> tag. A table consist of rows and columns, which can be set using one or more <tr>, <th>, and <td> elements. A table row is defined by the <tr> tag. To set table header, use the <th> tag.
In HTML, table background color is specified using Cascading Style Sheets (CSS). In particular, you use the CSS background-color property to set the background color for your table. You can also specify a separate background color for your table rows and table cells if you like.
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 It should be Elements(Plural) not Element(Singular)
document.getElementsByClass('metric')
hope this will solve your query.
if need any other help, just comment here I will try to solve
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With