javascript - Plugin tooltipster - Trunkate Title -
i using plugin "tooltipster" truncate title 30 characters , add together hellips.
i have list of 3 links. below code , added link illustration
$('.tooltip').tooltipster({ animation: 'fade', delay: 200, touchdevices: false, trigger: 'hover', position: 'bottom', theme: 'tooltipster-shadow' }); $('.box a').each(function(){ if ($(this).attr('title').text().length > 20) { $(this).attr('title').text($(this).text().substr(0, 17)); $(this).attr('title').append(' ...'); } });
http://jsfiddle.net/rttug/
thank much!
you should execute scripts after dom ready, utilize $(document).ready(function(){})
or $(function(){})
to attribute value utilize $.attr('attribute')
instead of $.attr('attribute').text()
to update attribute value utilize $.attr('attribute', 'new value')
instead of $.attr('attribute').text('new value')
your new code this:
$(function(){ $('.box a').each(function(){ var title = $(this).attr('title'); if (title.length > 20) { $(this).attr('title', title.substr(0, 17) + '...'); } }) $('.tooltip').tooltipster({ animation: 'fade', delay: 200, touchdevices: false, trigger: 'hover', position: 'bottom', theme: 'tooltipster-shadow' }); })
http://jsfiddle.net/8vpuk/
javascript jquery tooltipster
No comments:
Post a Comment