I'm having some trouble with using the .index()
inside of a .hover()
function. Thanks for any help.
$("#myUL li").hover(
function () {
//this logs a li element as it should
$(this).log();
//this reports that it's not a valid function, why?
$("#myUL").index(this).log();
//when i do it this way...
var foo = $("#myUL").index(this);
//this returns -1. Why can't it find the li?
$(foo).log();
},
function () {
}
);
If it makes a difference, this is the code I'm using for the .log()
function:
jQuery.fn.log = function (msg) {
console.log("%s: %o", msg, this);
return this;
};
:edit: per the comment, here is the html:
<ul id="myUL">
<li>
<div><img src="images/img1.jpg"/></div>
</li>
<li>
<div><img src="images/img2.jpg"/></div>
</li>
<li>
<div><img src="images/img3.jpg"/></div>
</li>
</ul>