tags:

views:

32

answers:

2

the problem:

I want to use jquery to add a class of 'warm' to any li's neighboring to a li.hot

<ul>
    <li></li> * ? (unknown amount of li's)
    <li></li>
    <li class="hot"></li>
    <li></li>
    <li></li> * ? (unknown amount of li's)
</ul>
+5  A: 

If by "neighboring", you meant the previous and next elements then you can use .prev() and .next() selectors.

var liHot = $("li.hot");
liHot.prev("li").addClass("warm");
liHot.next("li").addClass("warm");
rahul
and in one statement: $('li.hot').prev("li").addClass("warm").end().next('li').addClass('warm');
pixeline
A: 
$('li.hot').prev().addClass('warm');
$('li.hot').next().addClass('warm');

I know it's basic, but you get the idea.

Raithlin