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>&nbsp;/&nbsp;</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 Web Developer (WordPress, Webflow, Weebly & Custom), Front-end / 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.