"": . , , DIV. , .
, :
<ul class="timeList">
<li class="timeSlot">8:00</li>
<li class="timeSlot">9:00</li>
...
<li class="timeSlot">18:00</li>
</ul>
:
- 5 , # 5 MORE.
- # 5 LESS
- LESS, # 5 MORE
jQuery, , , , , .
1 :
jQuery(".someClass").children(":gt(4)").hide();
5- . : LI, , 5- . , .
, , , , :
jQuery(function () {
jQuery(".timeList").each(function () {
jQuery(this).children(":gt(4)").css('color','red');
});
});
: http://jsfiddle.net/7PeVj/
# 2 , 5 MORE. , . , , 5, jQuery append(), .
. , , timeSlots
jQuery(".timeList").each(function () {
var theList = jQuery(this);
var kids = theList.children(".timeSlot");
kids.filter(":gt(4)").css('color','red');
if (kids.length > 5) {
theList.append('<li class="slotMoreLess">MORE</li>');
}
});
: http://jsfiddle.net/7PeVj/2/
, "" MORE/LESS, . jQuery on() , .
: http://jsfiddle.net/7PeVj/4/
, , . text() MORE LESS MORE .