indexzero
10/3/2013 - 6:04 PM

Using jQuery.data for fun and profit

Using jQuery.data for fun and profit

  jQuery.data(document.body, 'recent-searches', [
    { query: 'Columbia', place: '1234', from: '2013-10-15' },
    { query: 'Obama', place: '4566', from: '2013-10-14' },
    { query: 'Things', place: '334skj', from: '2013-10-13' },
    { query: 'Other Things', place: 'sdkfjs', from: '2013-10-12' },
    { query: 'Javascript', place: 'lkasjdf', from: '2013-10-11' }
  ]);

  setTimeout(function () {
    var arr = jQuery.data(document.body, 'recent-searches');
    console.dir(arr);
    arr.forEach(function (obj) {
      console.dir(obj);
      var el = $('<div>' + obj.query + '</div>')
      el.on('click', function (el) {
        $('#search-header').text([obj.query, obj.place, obj.from].join(' '));
      });
      
      $('#other-page-container').append(el);
    });
  }, 1000);