foreach - Create one list item for each year using JQuery -


i building web app visual representation of data sorted year, , have ordered list of years in html, i.e.:

<ol id="years">     <li>1900</li>     <li>1901</li>     <li>1902</li> 

    <li>1950</li> </ol> 

i prefer list automatically generated on page load javascript, it's year range change on time, , don't want risk javascript , html getting out of sync.

for other functions declaring variables firstyear , lastyear match first , last items in list, i.e.:

var firstyear = 1900; var lastyear = 1950; 

i've tried base code on looks a similar question have not quite figured out how adapt app's requirements.

if can me write function this, appreciated.

try :

var firstyear = 1900; var lastyear = 1950; for(var =firstyear; i<=lastyear; i++) {        $('#years').append('<li>'+i+'</li>') } 

Comments