How to exclude a class when using the :first-child and :last-child selectors in jQuery -


i have jquery problem can't seem work out on own - while know how style first , last elements of unordered using :first-child , :last-child selectors, i'd include caption inside ul well…

i need put caption before or after li elements inside ul, makes jquery apply :first-child or :last-child p element depending on sits in relation list of li elements.

basically, i'd find out how make :first-child , :last-child selector exclude p element altogether. having looked around, i've been able work out .not() need, haven't been able work.

for example, not work -

$('ul.grid li:first-child').not($(.caption)).addclass('narrow'); 

i'd grateful if able me out based on below

jquery( document ).ready( function ($) {     $('ul.grid li:first-child').addclass('narrow');     $('ul.grid li:last-child').addclass( 'narrow' ); }); 

html:

<ul class="grid">     <p class="caption">caption text</p>     <li>         <img src="images/test1.jpg" alt="1" />     </li>     <li>         <img src="images/test2.jpg" alt="2" />     </li>     <li>         <img src="images/test2.jpg" alt="2" />     </li> </ul>    

ok, think understand. work?

$(function() {     var ul = $('ul.grid');     ul.find('li:first').addclass('narrow');     ul.find('li:last').addclass('narrow'); }); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -