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

438
Views
How to edit CSS of a last row in a table?

this is the table that I created. I'm pretty much a beginner in Web programming so any help would be appreciated. I'm trying to figure out how do I add CSS to the last row in the created table. What this code does is basically makes a table with 4 rows and it calculates number squared, its factorial and sum of elements in a row. At the bottom of the table is row which contains sum of elements for each column. How do I add styles to, for instance, make background color to be darkblue? Thanks in advance:)

  function tablica() {
        var sum1 = 0,
            sum2 = 0,
            sum3 = 0;
        var nr = document.getElementById("broj").value
        if (nr < 2) {
            document.getElementById("rezultat").innerHTML = "Prilagođeno samo za rad s brojevima većim od 1";
            window.alert("Unijeli ste broj " + broj.value + ", a taj broj je manji od 2...");
        } else {
            var rez = "<table id='tablica' class='tabClass'><tr><th>N</th><th>N²</th><th>N!</th><th>Suma</th></tr>";
            var faktorijela = 1;
            for (var i = 1; i <= nr; i++) {
                let val1 = i;
                let val2 = i * i;
                let val3 = (faktorijela = faktorijela * i);
                rez = rez + "<tr><td>" + val1 + "</td><td>" + val2 + "</td><td>" + val3 + "</td><td>" + (val1 + val2 + val3)
                "</td></tr>";
                sum1 = sum1 + val1;
                sum2 = sum2 + val2;
                sum3 = sum3 + val3;

            }
            rez = rez + "<tr><td>" + sum1 + "</td><td>" + sum2 + "</td><td>" + sum3 + "</td><td>∑</td></tr>";
            rez = rez + "</table>";

        }
        var rezTablica = document.getElementById("rezultat");
        rezTablica.innerHTML = rez;
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use the :last-child or :last-of-type pseudo-class.

table {
  border-collapse: collapse;
}

table td {
  padding: 5px;
}

table tr:last-child {
  background: salmon;
}
<table>
  <tbody>
    <tr>
      <td>col1</td>
      <td>col2</td>
    </tr>
    <tr>
      <td>col1</td>
      <td>col2</td>
    </tr>
    <tr>
      <td>col1</td>
      <td>col2</td>
    </tr>
  </tbody>
</table>

about 4 years ago · Juan Pablo Isaza Report

0

if you want to edit the last element in rows you can use :last-child to select the last row.

you can read more here.

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!