html - load() multiple elements from url into an array jQuery -
i'm far expert on js , need loading multiple elements' content other pages of same domain. have now:
$(document).ready(function(){ $('div.container').each(function(){ var link = $(this).find('a').attr('href'); var table = $('<table></table>').addclass('params'); for(i=1; i<4; i++){ var row = $('<tr />').addclass('param_' + i).html('<td class="val" />'); table.append(row); }; $(this).append(table); $(this).find('tr.param_1 td.val').load(link + ' #content1'); $(this).find('tr.param_2 td.val').load(link + ' #content2'); $(this).find('tr.param_3 td.val').load(link + ' #content3'); }); });
it works, can see there multiple div containers on current page , each 'div.container' needs multiple elements placed in respective urls. scan url once , elements' content array, doesn't load every page multiple times, increases loading time much.
or maybe have other suggestions on doing it. keep in mind have understanding of jquery, nothing else. answers found vague.
thanks in advance. appreciated.
i think , have use local storage .
below code may helped .
$(this).find('td[id^="tr_id_"]').each(function(key,val){ if (localstorage.getitem("tr_id_"+key) === null) { /// populate data in td elements via local storage . document.getelementbyid("tr_id_"+key).innerhtml = localstorage.getitem("tr_id_"+key); }else{ $(this).find('tr#tr_id_'+key).load(link); /// store data in local storage . var html_content = document.getelementbyid("tr_id_"+key).innerhtml; localstorage.setitem("tr_id_"+key,html_content); } });
Comments
Post a Comment