I am creating a function that returns a jQuery object of all of the elements of a given selector across paged content.
const getPagedContent = async (base, selector) => { let elements = []; let lastPage = 1; let page = 0; while (lastPage > page) { page++; let response = await got(`${base}/page/${page}`); let html = new jsdom.JSDOM(response.body); elements.push($(html).find(selector)); lastPage = getLastPage(html); } return elements; } However, this does return a jQuery object with all the elements but (obviously) an array with multiple jQuery objects. How can I add the results from each page so I can return one jQuery object with all the elements?
Edit: Attempting to use .add returns a jQuery object with a length of 0. I am not sure how to adopt add for multiple doms.
const getPagedContent = async (base, selector) => { let elements = $(); let lastPage = 1; let page = 0; while (lastPage > page) { page++; let response = await got(`${base}/page/${page}`); let html = new jsdom.JSDOM(response.body); elements.add($(html).find(selector)); lastPage = getLastPage(html); } console.dir(elements); console.log('Items length:', elements.length); return elements; } jQuery {} Items length: 0
.findnot an object of jQuery elements? I am looking to merge the elements from multiple pages to look as if the results from.findwas ran on all pages.