I have text inputs and textareas that I would like to show the user how many characters they have used out of the limit. So I add a tooltip to every element that has a data-maxlength attribute. I create the tooltip for the current text input that includes the length and the maxlength values(x / 250 characters) every time a key is pressed. The problem is that the value of the title attribute of the tooltip never changes after you stop typing for the first time. Here is a jsFiddle to show you.
The jQuery
$(document).ready(function(){
$('[data-maxlength]').each(function(){
$(this).on('keyup', function(){
$(this).tooltip({
selector: 'data-toggle="tooltip"',
placement: 'bottom',
trigger: 'manual',
title: $(this).val().length + ' / ' + $(this).data('maxlength') + ' characters used.'
});
$(this).tooltip('show');
});
});
});
The HTML:
<textarea name="description" data-maxlength="250"></textarea>
Thanks for your time.