Jonathan Vanherpe (T & T nv)
Mon, 22 Feb 2010 05:14:28 -0800
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.beI 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