I am trying to write a simple hover function (please don't suggest another, I have specific needs). I have the hover work so that it will show to the right of the list item that it is hovering. The style of the page shows a left navigation where the ul background looks like a solid block. This means that I need my hover to be to the right of the whole ul, not just the li I am over incase it is a short one. I am trying to get the parent of the li, but I am getting an error this.parent is not a function. How do I get the parent ul of a li so I can get it's position.
my li has a class of .left-nav-item
this.myhover = function () {
this.xOffset = -10; // x distance from mouse
this.yOffset = 10; // y distance from mouse
$(".left-nav-item").unbind().hover(
function (e) {
this.top = (e.pageY + yOffset);
this.left = (e.pageX + xOffset);
alert(this.title);
this.parent().css('background-color', 'red');
$('body').append('<p id="new">My Hover Text</p>');
$('p#new').css("top", this.top + "px").css("left", this.left + "px").css("position", "absolute").fadeIn("slow");
},
function () {
//$("p#new").fadeOut("slow").remove();
}
).mousemove(
function (e) {
this.top = (e.pageY + yOffset);
this.left = (e.pageX + xOffset);
//$("p#new").css("top", this.top + "px").css("left", this.left + "px");
}
);
};
jQuery(document).ready(function ($) { myhover(); });