Skip to content

jQuery dependant function to limit the length of a text string inside a dom element. Doesn't trim words.

License

Notifications You must be signed in to change notification settings

pfmescher/limitTextLength

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

limitTextLength

jQuery dependant function to limit the length of a text string inside a dom element. Doesn't trim words. It inserts "..." after the max characters and provides callbacks for when the mouse hovers over them and when the mouse leaves. Default behaviour is to replace the "..." with the remainder of the text when the mouse hovers, and get back to the original state when the mouse leaves.

Usage

limitTextLength({
  element: jQuery("selector"), //element is necessary. Can be a jQuery element, dom node or jQuery selector
  maxLength: 25 //Max string length (not including ...).
});

Optional parameters:

enter: Callback function when the mouse enters the span containing the "...". The callback "this" is set to the span, and gets passed the trimmed text and the original text as first and second parameters.

leave: Same as enter but triggered on mouseleave

class: CSS class for custom styling the span. Empty by default.

css: An object containing CSS directives to be added to the span.

Working example: http://jsfiddle.net/K8KgR/4/

About

jQuery dependant function to limit the length of a text string inside a dom element. Doesn't trim words.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published