Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:55:13+00:00 2026-05-13T09:55:13+00:00

I was wondering if anybody knows how to select using js the complete table,

  • 0

I was wondering if anybody knows how to select using js the complete table, so that the user can right-click on the selection, copy it to the clipboard and then paste it on Excel. If you select the table manually, the process works perfectly. But sometimes, if the table height is a few times larger than the screen, selecting it dragging the mouse gets tedious. So, I want to give the users the possibility to click on a “select the whole table” button and everything gets ready to be copied.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:55:13+00:00Added an answer on May 13, 2026 at 9:55 am

    Yes. It’s not too tricky, and the following will work in all mainstream browsers (including IE 6, and indeed 5):

    (Updated 7 September 2012 after Jukka Korpela’s comment pointing out that the previous version didn’t work in IE 9 standards mode)

    Demo: http://jsfiddle.net/timdown/hGkGp/749/

    Code:

    function selectElementContents(el) {
    	var body = document.body, range, sel;
    	if (document.createRange && window.getSelection) {
    		range = document.createRange();
    		sel = window.getSelection();
    		sel.removeAllRanges();
    		try {
    			range.selectNodeContents(el);
    			sel.addRange(range);
    		} catch (e) {
    			range.selectNode(el);
    			sel.addRange(range);
    		}
    	} else if (body.createTextRange) {
    		range = body.createTextRange();
    		range.moveToElementText(el);
    		range.select();
    	}
    }
    <table id="tableId" border="1">
    	<thead>
    		<tr><th>Heading 1</th><th>Heading 2</th></tr>
    	</thead>
    	<tbody>
    		<tr><td>cell 1</td><td>cell 2</td></tr>
    	</tbody>
    </table>
    
    <input type="button" value="select table" onclick="selectElementContents( document.getElementById('tableId') );">
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was wondering if anybody knows of a nice scripting language that can be
I'm wondering if anybody knows of a code snippet anywhere that allows you to
Wondering if anybody knows where I can find any high resolution pictures for iPhone,
Anybody knows of a tool that can be used to automatically build diagrams of
I was wondering if anybody knows the total length that a post global could
I was wondering if anybody knows of a way to retrieve the actual T-SQL
I've downloaded the dll's for ImageMagick and am wondering if anybody knows of some
Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality.
I am using successfully the mobylette rails gem: https://github.com/tscolari/mobylette I was wondering if anybody
I was wondering if anybody knows how I would go about detecting when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.