Reputation: 21
I am using the plugin "tooltipster" but I would like to truncate the title to 30 characters and add hellips.
I have a list of 3 links. Below is the code and added a link to example
$('.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(' ...');
}
});
thank you very much!
Upvotes: 0
Views: 272
Reputation: 796
$(document).ready(function(){})
or $(function(){})
$.attr('attribute')
instead of $.attr('attribute').text()
$.attr('attribute', 'new value')
instead of $.attr('attribute').text('new value')
Your new code will be like 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'
});
})
Upvotes: 1