jQuery Apply to all but First

Glenn Glenn's Blog 0 Comments

A quick snippit for you to apply jQuery selection to all but first element:-


<script type="text/javascript">
$(document).ready(function(){
  $('ul.selector :not(:first-child)').each(function(){
	$(this).prepend("<span> / </span>");
}); 
  });
</script> 

As per our example this is useful in unordered / ordered lists and therefor menus etc. We are prepending a span with x2 spaces to every li except the first.

About the Author
jQuery Apply to all but First jQuery Apply to all but First 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced WordPress Web Developer, Front-end and Back-end Developer & New Media Specialist with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries built up over a number of years.

Leave a Reply

Your email address will not be published. Required fields are marked *