Can't understand this... Want to make a image appear on active link

Can't understand this... Want to make a image appear on active link

Hi everyone!

I started using jQuery yesterday so im a noob.

I have a navigation bar, and i want it to display a background image on the active menu item. (Like the top most menu on this website, it has a little blue underline)

So i got this function:

  1. function displayBgImg() {
  2.         for (var i=0; i<$("ul#nav_prim a").length; i++) {
  3.                 if ($("ul#nav_prim a")[i].href == document.URL) {
  4.                         $("ul#nav_prim a")[i].css("background-image", "url(images/nav_bg.gif)");
  5.                 }
  6.         }
  7. }

Line 2: It loops though all the <a> tags in an <UL> with id nav_prim. (The <a> tags are inside of <li>'s in the <ul>.

Line 3: I check to see if the <a> tag's href atribute is the same as the URL of the page, if it is

Line 4: i want that specific <a> tag's background-image to be images/nav_bg.gif.

I can't get it to work. In firefox i get the error " $("ul#nav_prim a")[i].css" is not a function.

Why is that? Can anyone please help me? As i've said im new to jQuery and Javascript in general aswell.

Thanks for any advice :)