Get sliced list items
Description
The following code shows how to slice a UL list and add style.
Example
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type='text/javascript'>
var tmpExample = {
ready : function() {<!-- ww w. j a v a 2 s . c om-->
$('ul#uiID li').slice(0, 4).addClass('justAdd');
}
};
$(document).ready(tmpExample.ready);
</script>
<style type='text/css'>
ul#uiID {
list-style: none;
margin: 0;
padding: 0;
}
ul#uiID li {
margin: 1px;
padding: 3px;
}
li.justAdd {
background: #fcc16e;
}
</style>
</head>
<body id='tmpExample'>
<ul id='uiID'>
<li class='liClass1'>A</li>
<li class='liClass1'>B</li>
<li class='liClass1'>C</li>
<li class='liClass1'>D</li>
<li class='liClass2'>E</li>
<li class='liClass2'>F</li>
<li class='liClass2'>G</li>
<li class='liClass2'>H</li>
<li class='liClass3'>I</li>
<li class='liClass3'>J</li>
</ul>
</body>
</html>