Jump to content

using ajax for external content and limit number of items shown


soddengecko

Recommended Posts

hi all

 

I am loading my content externally into a div to show recent updates to my site. at the moment i am deleting old entries so that i am only showing 10 updates at a time.

 

the data is a simple list of items. is it possible to have javascript go through this list and only output only the first ten entries in the <ul>?

are you saying that the items currently are in an ul, or that you want to output them in an ul?

is the list being recieved through ajax?  what form is it being recieved in: json, comma separated, newline separated, etc.

 

You will probably have to write some code to break the individual items out and create an array, then you can just  use a loop to build the list, then innerHTML:

<script>
var myUL = '<ul>';
for (var i=0; i<10; i++) {
    myUL += '<li>' + listitem[i] + '</li>';
}
myUL +=  '</ul>';
document.getElementById('myDIV').innerHTML = myUL;
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.