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

  • Home
  • SEARCH
  • 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
Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality.
I'm just wondering if anybody knows if Apple provides deals to enterprises wanting to
I'm wondering if anybody knows of a way to conditionally execute a program depending
I was wondering if anybody knew of a method to configure apache to fall
I was wondering if anybody out there had some good tips/dos and don'ts for
I'm looking into writing a audio syntesizer in Java, and was wondering if anybody
Wondering if anyone can help me with this annoying but trivial (in terms of
Hey, I was wondering if anybody knew how to alter the following XSL stylesheet
I would like to ask if anybody has any knows how to use 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.