quick jquery help

Soldato
Joined
12 May 2007
Posts
3,896
Location
Bristol
I'm not that great with jquery yet but I need the following quickly and someone will probably be able to give me the answer before I can get it working by myself.

I just need to use jquery to search for any 'li a' element which has class 'selected'. Then, it needs to target the 'li' element before it and add a class to it.

Code:
Before...
<ul>
  <li><a href="#">Link</a></li>
  <li><a href="#" class="selected">Link</a></li>
</ul>

After..
<ul>
  <li class="besideSelected"><a href="#">Link</a></li>
  <li><a href="#" class="selected">Link</a></li>
</ul>

Any help would be appreciated.
 
Thanks for the suggestion. :)

I ended up moving the selected class to the li instead of li a anyway so it worked with the following.
Code:
$("li.selected").prev().addClass("besideSelected");

I tried your method on the li a though and it certainly does work. Thank you!
 
Last edited:
Back
Top Bottom