Add a class to first query result How can I add a class to first query result?

$number_of_slides = '3';
$slides_result = db_query_range("SELECT nid FROM {term_node} WHERE tid = 1 ORDER BY nid DESC", array(), 0, $number_of_slides);
while ($slidesid = db_result($slides_result)) {
$slides = node_load($slidesid);
print $slides-&gt;title;
}


anyway I tried this but it doesn't work.

&lt;html&gt;
&lt;head&gt;
&lt;script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;
$('.item')
    .eq(0).addClass('first').end()
    .eq(-1).addClass('last').end();
&lt;/script&gt;
&lt;style type="text/css"&gt;
.first, .last{
background-color:#0099FF;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="item"&gt;aaa&lt;/div&gt;
&lt;div class="item"&gt;bbb&lt;/div&gt;
&lt;div class="item"&gt;ccc&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
If you're going to use jQuery anyway, why not just use the .first and .last selectors?

$('.item').first().addClass('first'); 
$('.item').last().addClass('last');