$('selector')[index] returns the actual DOM element, while
$('selector').eq(i) returns a jquery object (you can see a jquery object
as some sort of a shell around the actual DOM node that the jquery
functions work on).
You can only use the jquery .css() function on jquery objects, and not
directly on DOM nodes. I think it's easiest to explain by using the
console in firebug:
type $("ul#nav_prim a")[1] and $("ul#nav_prim a").eq(i) into the console
and you'll see that firebug returns a slightly different result.
As for ($("ul#nav_prim a")[i]==document.URL), I don't think this is the
proper way to do it, but if it works, great (just don't assume this will
work in all browsers, test it first).
Jonathan
tooone777 wrote:
Jonathan Vanherpe (T& T NV) wrote:
tooone777 wrote:
$("ul#nav_prim a")[i]...
you need to use
$("ul#nav_prim a").eq(i)...
or
$("ul#nav_prim a:eq("+i+")")...
Jonathan
--
Jonathan Vanherpe - Tallieu& Tallieu nv - jonat...@tnt.be
I changed my code to the way you suggested, the error message is now gone
but the background image doesn't change.
However, if it looks like this:
function displayBgImg() {
for (var i=0; i<$("ul#nav_prim a").length; i++) {
if ($("ul#nav_prim a")[i] == document.URL) {
$("ul#nav_prim a").eq(i).css("background-image",
"url(images/nav_bg.gif)");
}
}
}
it works!
Notice that i only have "eq(i)" on line 4 but not on line 3.
Do you mind explaining what's happening when i use ".eq(i)" instead of
"[i]"?
Thank you very much for the help Jonathan :)
--
Jonathan Vanherpe - Tallieu & Tallieu nv - jonat...@tnt.be