0

in a table which has horizontal scrolling, how can one best jump to the last column without adding a specific ID/class/ref to the last column itself?

E.g. I can do:

document.getElementsByClassName('makeStyles-tableCell-251')[document.getElementsByClassName('makeStyles-tableCell-251').length -1].scrollIntoView()

but instead I'd like to reference only the table.

Thanks!

2 Answers 2

2

You're nearly there. Try using the :last-child selector.

document.querySelector('#table-you-want tbody tr:last-child').scrollIntoView()
Sign up to request clarification or add additional context in comments.

Comments

1

You can use css psuedo selector :last-child for getting the last element.

document.querySelector('table tr td:last-child').scrollIntoView()
table tr td {
  min-width: 100px;
}
<table id="my-table">
  <tr>
    <td>column 1</td>
    <td>column 2</td>
    <td>column 3</td>
    <td>column 4</td>
    <td>column 5</td>
    <td>column 6</td>
    <td>column 7</td>
    <td>column 8</td>
  </tr>
</table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.