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 7524691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:08:05+00:00 2026-05-30T03:08:05+00:00

I’m trying to make some html with css pages (I’m new to both) and

  • 0

I’m trying to make some html with css pages (I’m new to both) and I want to add styles to a table header with column long names, this names are required to be long, but the column width is fixed, making these columns without css would show them with text wrapping so the row height would show just NOT nice. I’m trying to find a nice way to display the table. What comes to my mind, is “cut” the name of the column veryLongColumName to veryLong... and on hover of the table header, display it as they are originally, how can I do this? do I need to begin learning JavaScript >> jQuery in order to do this? Any sample code I can use?

If you have a better idea about how to display nicely that content it is welcome.

I have no idea how to do this as it seems that there need to be data manipulation (so I need JavaScript or jQuery); how ever, I think that having two div tags with the shortened name and the original name in another and display one or other depending on the mouse hover will do the work but I don’t know how to make that happen (is this also jQuery?).

Thanks in advance.

http://jsfiddle.net/byakku/Q5V98/1/

  • 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-30T03:08:06+00:00Added an answer on May 30, 2026 at 3:08 am

    I tried to implement it in plain javascript without any lib/plugin and below is what I have,

    Solution using plain javascript (without jQuery) DEMO

    The above demo code can be reduced a lot by using jQuery,

    Solution using jQuery – DEMO

    Using jQuery:

    function shortHandTableHeaders(tableID, limit) {
    
        var ths = $('#' + tableID + ' thead tr th');        
        var content;
    
        ths.each (function () {
            var $this = $(this);
            content = $this.text();
    
            if (content.length > limit) {
               $this.data('longheader', content);
               $this.text (shortHandHeaderTxt(content, limit));
    
               $this.hover (
                   function() {
                       $(this).text($this.data('longheader'));
                   },
                   function () {
                       $(this).text(shortHandHeaderTxt($this.data('longheader'), limit));
                   }
               );
             }
        });
    }
    
    function shortHandHeaderTxt(txt, limit) {
        return txt.substring(0, limit - 3) + "...";
    }
    

    Below is the another implementation without jQuery,

    function shortHandTableHeaders(tableID, limit) {
    
        var tableEl = document.getElementById(tableID);
        var thead = tableEl.getElementsByTagName("thead");
        var thtrs = thead[0].getElementsByTagName("tr");
        var ths, content;
    
        for (var i = 0; i < thtrs.length; i++) {
            ths = thtrs[i].getElementsByTagName("th");
    
            for (var j = 0; j < ths.length; j++) {
                content = ths[j].innerHTML;
    
                if (content.length > limit) {
                    ths[j].title = content;
                    ths[j].innerHTML = shortHandHeaderTxt(content, limit);
                    addEventHandler(ths[j], 'mouseover', function() {
                        this.innerHTML = this.title;
                    });
    
                    addEventHandler(ths[j], 'mouseout', function() {
                        this.innerHTML = shortHandHeaderTxt(this.title, limit);
    
                    });
                }
            }
        }
    }
    
    
    function addEventHandler(el, eType, handler) {
        if (el.addEventListener) { // W3C, FF  
            el.addEventListener(eType, handler, false);
        } else if (el.attachEvent) { // IE  
            el.attachEvent('on' + eType, function() {
                handler.call(el);
            });
        }
    }
    
    function shortHandHeaderTxt(txt, limit) {
        return txt.substring(0, limit - 3) + "...";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into

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.