looking for some help please with the JQuery CSS selector. I want to identify the first and last LI from the main UL list and alter the CSS class. The first should be
class="grid_4 alpha"
and the last
class="grid_4 omega"
<ul>
<li id="linkcat-2" class="grid_4 this should be alpha"><h4 class="widgettitle">Blogroll</h4>
<ul class='xoxo blogroll'>
<li><a href="http://wordpress.com/">WordPress.com</a></li>
<li><a href="http://wordpress.org/">WordPress.org</a></li>
</ul>
</li>
<li id="linkcat-2" class="grid_4"><h4 class="widgettitle">Blogroll</h4>
<ul class='xoxo blogroll'>
<li><a href="http://wordpress.com/">WordPress.com</a></li>
<li><a href="http://wordpress.org/">WordPress.org</a></li>
</ul>
</li>
<li id="linkcat-2" class="grid_4"><h4 class="widgettitle">Blogroll</h4>
<ul class='xoxo blogroll'>
<li><a href="http://wordpress.com/">WordPress.com</a></li>
<li><a href="http://wordpress.org/">WordPress.org</a></li>
</ul>
</li>
<li id="linkcat-2" class="grid_4 this should be omega"><h4 class="widgettitle">Blogroll</h4>
<ul class='xoxo blogroll'>
<li><a href="http://wordpress.com/">WordPress.com</a></li>
<li><a href="http://wordpress.org/">WordPress.org</a></li>
</ul>
</li>
</ul>
I just cannot get the right JQuery.css functio to work.
Help much appreciated – I can add an id to the master ul if requyired
Use
:first-childand:last-childwith the child (>) selector:Bear in mind that classes can’t have spaces in them. This markup:
defines a list element that has two classes. If you want to select it you can use:
meaning select all the list elements that have both the grid_4 and alpha classes.