Here is a code snippet from my current project. I have dynamic elements loading into a container div through PHP from a MYSQL database.
<div id="itemContainer">
<div class="item">
test
</div>
<div class="item">
test
</div>
<div class="item">
test
</div>
<div class="item">
test
</div>
<div class="item">
test
</div>
<div class="item">
test
</div>
</div>
I want only 4 items to display at once, even if there are more in the list. I attempted to select all items after the fourth one using jQuery, but encountered some issues along the way. Your assistance would be greatly appreciated!
$(document).ready(function() {
var items = $('#weekly_best_selling').children('.itemContainer').length;
if (items > 6) {
$('#weekly_best_selling').children('.itemContainer').nextAll('.itemContainer').css( "background-color", "red" );
}
});