Title gets undefined when hovered (jQuery UI Tooltip) -
the following code run every second in setinterval:
for (i = 0; < mt1.length; i++){ $(mt1[i]).each(function(){ $(this).attr('title', $(this).attr('title').split(" ")[0] + " " + $(this).attr('title').split(" ")[1]); }); } title = "<img src='/flags/4x3/cn.svg' width='20px'' height='20px'> " + accounting.formatmoney(accounting.unformat($(this).html().split(" ")[0].substr(2).slice(0, -1)) * -6, '¥', 2, ",", "."); $(this).attr('title', title + '|' + $(this).attr('title')); what happening when not hovered, inspecting element shows correctly, text blinking every second stated in setinterval() method: <span title="55 tests |<img src='/flags/4x3/cn.svg' width='20px'' height='20px'> ¥1.90</span>
but after gets hovered, shows undefined instead of 55 tests. what's happening?
this shown in console.log after hovering:
undefined |<img src='/flags/4x3/cn.svg' width='20px'' height='20px'> ¥1.90 update:
seems tooltip (jqueryui tooltip) using has it, next code in beginning of page. does, turns | <br> move currency value next line:
$(function() { $( document ).tooltip({ content: function(callback) { callback($(this).prop('title').replace(/\|/g, '<br />')); } }) }); update: jsfiddle added:
[https://jsfiddle.net/hrklssgk/][1]
i'm not sure if needed code in setinterval, left it. here working fiddle: https://jsfiddle.net/hrklssgk/2/
notice we've changed array contain updated flag each element. once element has had it's title updated, not go through updating again until flag reverted.
var mt1 = [ [$("#la"), false] /* first element jquery, second flag if it's been updated */ ]; iterate through each element, , execute title-change if it's flag false:
mt1.foreach(function(){ if (!mt1[i][1]) { if setinterval not necessary, better off moving logic outside of setinterval , function called when needed
Comments
Post a Comment