Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to expand the text on a mouseover, then I'd suggest implementing the solution in jQuery as it means that the full text will be visible to those who don't have JS on (i.e. It's good for accessibility). The following is based on something we use on our website, and the full/shorted text is toggled by clicking on the text rather than hovering on it, but changing to a hover event should be fairly simple. </p> <p>Firstly wrap the text you want to auto expand/contract in a div/span with a class you can use to pick it up in jQuery later. </p> <pre><code>&lt;div class="autoShorten"&gt;An example is always better than description situation.&lt;/div&gt; </code></pre> <p>Then create the following jQuery function:</p> <pre><code>jQuery.fn.autoShorten = function() { return this.each(function(){ if ($(this).text().length &gt; 100) { var words = $(this).text().substring(0,100).split(" "); var shortText = words.slice(0, words.length - 1).join(" ") + "..."; $(this).data('replacementText', $(this).text()) .text(shortText) .css({ cursor: 'pointer' }) .hover(function() { $(this).css({ textDecoration: 'underline' }); }, function() { $(this).css({ textDecoration: 'none' }); }) .click(function() { var tempText = $(this).text(); $(this).text($(this).data('replacementText')); $(this).data('replacementText', tempText); }); } }); }; </code></pre> <p>This function also has the benefit of inserting the ellipsis on a word break rather than in the middle of the word</p> <p>finally in your <code>$(document).ready</code> function add <code>$('.autoShorten').autoShorten();</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload