Hi guys.
I have a DIV with let's say 10 paragraph.
I want to show just 5 paragraph on page load and let the users "view
more" (news) by clicking a button, or a link.
I ended up with these lines in 10 seconds but i can't made them
shorter. Can you?
pStart sets the nuber of elements to be showed.
pTotal is the total amount of Ps
when i click a#sa i toggle between two functions, one checks if the
number of paragraph is less then 5 and show them. the other function
in toggle do the rest.
Can you shorten these lines please (if you got time) and show me a
better way to do that?
Thanks in advance, hope i've been clear enough.
GC
$(function(){
var pStart = 4 //vuol dire 5 paragrafi, 0 incluso;
var pTotal = $("#newswrapper p").length;
doMore(pStart);
$("a#sa").toggle(function(){
doMore(pTotal);
},function(){
doLess(pStart);
});
function doMore(myparam){
$("#newswrapper p").each(function(i) {
if (i <= myparam){
$(this).show("fast");
}
});
}
function doLess(myparam){
$("#newswrapper p").each(function(i) {
if (i > myparam){
$(this).hide("fast");
}
});
}
});