I am designing a menu for my website where it will appear on the left side of the web. The menu will consist of X <li>
items, each with an icon. When I hover over each <li>
, I want to display X data-id associated with that item along with the icon.
For example:
<ul><li data-id="My Profile">ICON</li></ul>
On mouseover:
<ul><li>ICON + My Profile</li></ul>
I have tried implementing this functionality but it seems to be not working correctly. Here is the example: http://jsfiddle.net/pqa84nec/1/
This is the JavaScript code I am using:
$("#menu").each(function() {
$(this).find('li').each(function(){
var oldData = $(this).html();
var data = $(this).attr("data-id");
var that = this;
$(this).mouseover(function() {
setTimeout(function() {
$(that).html(oldData+data);
}, 100);
});
$(this).mouseout(function () {
$(this).html(oldData);
});
});
});
Can someone offer me some assistance with this issue?
P.S.
It appears that there is a bug in the code:
https://i.sstatic.net/fcgzz.png
Thank you!