Add a class to first div using jQuery

rachiieee

New Member
How to add a class to first div using jQuery. I Tried following code but doesn't work for me.maybe I'm missing something.\[code\]<html><head><script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script><script>$('.item') .eq(0).addClass('first').end() .eq(-1).addClass('last').end();</script><style type="text/css">.first, .last{background-color:#0099FF;}</style></head><body><div class="item">aaa</div><div class="item">bbb</div><div class="item">ccc</div><div class="item">ddd</div><div class="item">eee</div></body></html>\[/code\]Edit: Thanks to everyone, is there anyway to add a class to rest of DIVs?
 
Back
Top