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>?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.