3

Using the JavaScript sample found in this stack overflow post you can have a button that automatically selects a table. This selected table can then be copied to the clipboard.

My users will be copying this data into an Excel template and do not need the header information (<th></th> or <thead></thead>).

My table looks something like this:

<table class="sortable">
<thead>
  <tr><th>Person</th><th>Monthly pay</th></tr>
</thead>
<tbody>
  <tr><td>Bob</td><td>£12,000</td></tr>
  <tr><td>Doug</td><td>£8,500</td></tr>
  <tr><td>Sam</td><td>£9,200</td></tr>
  <tr><td>Nick</td><td>£15,300</td></tr>
</tbody>
<tfoot>
  <tr><td>TOTAL</td><td>£45,000</td></tr>
</tfoot>
</table>

How would I go about unselecting the header information?

UDPATE1

The key is to select the tbody (assuming you Do not want tfoot).

<input type="image" src="table.png" name="image" onclick="selectElementContents( document.getElementById('theebody') );">
1
  • 1
    do you need <tbody> and <tfoot>? Or just <tbody>? Commented Sep 17, 2010 at 20:03

1 Answer 1

2

If the <table> has a <thead> and <tbody>, you could just select the <tbody>. However if you have header row(s) as sibling of other rows... here is a good start on how to set the range with more control.

Sign up to request clarification or add additional context in comments.

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.