Using JavaScript/jQuery to populate the list from an array and loading more items on 'load more' button click? -
i have list of array in javascript , need to:
- use javascript and/or jquery populate first 5 courses of list array included (can use same image courses)
- make 'load more' button work, loading 5 additional courses each click
- sort courses alphabetically before listing them
document.getelementbyid('load-courses').innerhtml = courses[1];
i've been trying use different things document.getelementbyid (it @ bottom in javascript in jsfiddle) showing either undefined or [object object]. know not simple populate list.
https://jsfiddle.net/0jlztmfn/
this below list needs @ end. i've done styling , can make needed styling changes later can't find out how populate 5 on first load , rest: load 5 more on each click , sort alphabetically before listing. i'm not sure if using span inside html correct either load list in need display title, description, image in styles. way able style them before/after listing courses?
thanks
document.body.innerhtml = "abc"; // replaces body content "abc" , takes value string. change last line in .js file , this:
document.getelementbyid('load-courses').innerhtml = courses[1].title;
jsfiddle link: https://jsfiddle.net/raushankumar0717/0jlztmfn/4/
update:
you can add image page:
document.getelementbyid('courseimg').src=courses[1].imagelink;
where courseimg id of image element.
jsfiddle demonstrating requirement: https://jsfiddle.net/raushankumar0717/0jlztmfn/7/
var courses = [ { "title": "crime risk new", "shortdescription": "donec sodales lorem. curabitur @ nulla nec sem volutpat accumsan placerat nec elit. ut bibendum dui vitae purus fringilla rhoncus. praesent volutpat felis vitae felis ultricies rhoncus. nulla maximus nibh vel enim ullamcorper aliquam. nam efficitur est nibh, id mollis nisl ullamcorper et.", "imagelink": "image1.jpg" }, { "title": "alternative ireland mergers statements practice", "shortdescription": "aenean iaculis vehicula sollicitudin. sed convallis, massa sit amet venenatis volutpat, arcu dolor volutpat neque, in lobortis arcu velit hendrerit ante. quisque accumsan luctus enim eu aliquam. quisque et dolor est.", "imagelink": "http://design.ubuntu.com/wp-content/uploads/ubuntu-logo32.png" }, { "title": "security leadership social", "shortdescription": "vivamus pellentesque semper arcu eu egestas. fusce lacinia velit quam, rhoncus turpis blandit sit amet. vivamus eros mi, malesuada vitae facilisis at, tincidunt in urna. morbi sodales @ nulla ac commodo.", "imagelink": "image1.jpg" }, { "title": "results regulation financial governance , within", "shortdescription": "in enim nunc, tempor congue ut, interdum consequat tortor. class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. nulla luctus sodales nulla, @ eleifend nibh fermentum eget.", "imagelink": "image1.jpg" }, { "title": "uk leadership professional instruments to", "shortdescription": "ut congue quam, eu hendrerit dolor. ut porta in nunc id porttitor. pellentesque iaculis pretium vulputate. aenean eu neque vestibulum, semper leo sed, porttitor sapien. etiam in justo eu risus scelerisque ultricies. nunc commodo est in scelerisque semper.", "imagelink": "image1.jpg" }, { "title": "workload witness data", "shortdescription": "vestibulum maximus et arcu eget congue. phasellus", "imagelink": "image1.jpg" }, { "title": "business savings control", "shortdescription": "etiam elementum auctor tellus.", "imagelink": "image1.jpg" }, { "title": "donor business professionalism positioning", "shortdescription": "phasellus ultrices tellus @ gravida tempor. mauris in augue dolor. pellentesque sit amet mauris vehicula, eleifend tellus eget, cursus lectus. suspendisse sed convallis ex, non tristique tellus.", "imagelink": "image1.jpg" }, { "title": "performance work preventing workload mergers data strategy", "shortdescription": "vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; sed ut ipsum ac sapien mollis ultrices vehicula magna sed augue feugiat, eget interdum dui feugiat. integer erat augue, lacinia vel ex a, consectetur lacinia nulla.", "imagelink": "image1.jpg" }, { "title": "enterprise compliance introduction and", "shortdescription": "nullam cursus, leo in cursus feugiat, leo urna mollis dui, eu pretium augue orci ut lorem.", "imagelink": "image1.jpg" }, { "title": "performance combinations continuous bpm data corporate", "shortdescription": "donec ornare nisi nec viverra lacinia. ut in pharetra est. suspendisse vestibulum, nisi eget bibendum porta, urna erat fermentum mi, ac efficitur turpis nisi ut lacus.", "imagelink": "image1.jpg" }, { "title": "and building spreadsheet international", "shortdescription": "phasellus odio arcu, lobortis vel dui et, tincidunt tristique mi. aenean et malesuada nibh.", "imagelink": "image1.jpg" }, { "title": "partnership acquisitions finance teams gift strategy", "shortdescription": "donec et arcu augue sollicitudin congue. ut suscipit, dui @ ultrices convallis, purus mauris dignissim lacus, dignissim dui justo eu turpis. proin eget orci porttitor, convallis nibh sit amet, posuere lacus. nunc vestibulum @ ante sit amet dignissim. curabitur quis quam tortor.", "imagelink": "image1.jpg" }, { "title": "for briefing financial uk in", "shortdescription": "donec volutpat justo maximus lorem volutpat, eget aliquam dolor cursus. maecenas porta fermentum rhoncus. aliquam porttitor enim iaculis congue dignissim. aenean @ ante nisl mattis efficitur. morbi vulputate lorem nec condimentum.", "imagelink": "image1.jpg" }, { "title": "ideas management mapping using skills and", "shortdescription": "aliquam sollicitudin, nunc vitae laoreet mattis, justo ante congue tortor, nec tempus tellus metus consequat enim. ut eget urna euismod, luctus augue laoreet, rutrum dui. vivamus egestas eleifend arcu facilisis gravida.", "imagelink": "image1.jpg" }, { "title": "career negotiating managing buying change? tax", "shortdescription": "donec purus odio, bibendum in rutrum sit amet, tincidunt justo. curabitur quis blandit elit. cras blandit felis scelerisque luctus vulputate. etiam purus mauris, mattis bibendum metus a, vehicula consequat enim.", "imagelink": "image1.jpg" }, { "title": "mergers , assessing accountants , ethical the", "shortdescription": "donec vel neque consequat, tincidunt risus quis, sodales erat. donec imperdiet urna in sollicitudin auctor. donec tristique dolor vel elit pulvinar imperdiet. nulla id nisi feugiat, tempus neque quis, dignissim augue.", "imagelink": "image1.jpg" }, { "title": "solving mergers business", "shortdescription": "donec maximus suscipit tellus. sed dolor metus, lobortis in ultricies eget, tincidunt in erat. curabitur faucibus hendrerit ex in eleifend. maecenas ligula mauris, bibendum vitae nisl eget, mattis consequat mi.", "imagelink": "image1.jpg" }, { "title": "promoting basics accounting", "shortdescription": "morbi sit amet diam dui molestie venenatis ac vitae tortor. class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. ", "imagelink": "image1.jpg" }, { "title": "building uk gaap world", "shortdescription": "nunc consequat dictum rutrum.", "imagelink": "image1.jpg" }, { "title": "principles new professional accountants", "shortdescription": "mauris luctus neque sit amet odio posuere porta. aliquam interdum augue dui, @ lobortis eros ultrices id. donec mattis posuere dui vitae sagittis. sed tempor aliquam nisi, vel semper odio.", "imagelink": "image1.jpg" }, { "title": "transformation charity solving dynamic guide", "shortdescription": "duis leo lectus, lacinia sodales semper eget, convallis ut nibh. in blandit orci lectus, @ imperdiet urna posuere nec. orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. nunc vel urna quis est varius auctor.", "imagelink": "image1.jpg" }, { "title": "megatrends , advantage", "shortdescription": "morbi consequat eu magna quis bibendum.", "imagelink": "image1.jpg" }, { "title": "the law protection control", "shortdescription": "proin lobortis, ante ut vestibulum posuere, tortor mauris iaculis nulla, ac commodo odio quam eu arcu. suspendisse @ fringilla purus, vitae pharetra ante. suspendisse mattis rhoncus gravida. etiam tincidunt elementum condimentum. vivamus id sagittis erat, tincidunt tristique elit.", "imagelink": "image1.jpg" }, { "title": "corporate ethical", "shortdescription": "vivamus et vulputate ipsum, id vulputate nisl. vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; vivamus lacus risus, egestas nec magna ornare, aliquam luctus nibh. morbi vel ullamcorper ex.", "imagelink": "image1.jpg" }, { "title": "succession ifrs ifrs cyber integrated and", "shortdescription": "mauris molestie nunc ut efficitur tincidunt. quisque consectetur tincidunt lorem, sit amet semper purus pellentesque non. pellentesque et volutpat sapien.", "imagelink": "image1.jpg" }, { "title": "for reacting understanding sme results the", "shortdescription": "praesent ac sagittis purus. etiam lacinia massa sed felis pulvinar, vitae consectetur tellus iaculis. nullam quis vulputate turpis.", "imagelink": "image1.jpg" }, { "title": "development accounting issues and", "shortdescription": "maecenas non pellentesque neque. donec maximus bibendum lectus vel eleifend. nullam fringilla vitae ex vel eleifend. nunc aliquet tempus sapien vitae consequat. donec pretium ipsum ut nunc ornare, tincidunt odio bibendum.", "imagelink": "image1.jpg" }, { "title": "tips financial planning", "shortdescription": "proin congue semper fringilla. cras risus ipsum, scelerisque sit amet nunc in, aliquam volutpat neque. maecenas imperdiet nunc sed libero congue, non fringilla sapien ultricies.", "imagelink": "image1.jpg" } ]; document.getelementbyid('courseimg').src=courses[1].imagelink; document.getelementbyid('coursetitle').innerhtml = courses[1].title; document.getelementbyid('descp').innerhtml = courses[1].shortdescription;
body { width:100%; height:100%; } #courseimg { width:25%; height:50%; display:inline-block; } .course { width:70%; height:50%; display:inline-block; }
<div class="courses-list"> <h3>courses</h3> <img id = "courseimg" src="" ></img> <div class="course"> <p id="coursetitle"> </p> <p id="descp"></p> </div> </div>
hope helps
Comments
Post a Comment