For pet-Dapp http://truffleframework.com/tutorials/pet-shop , I created a new html page which displays adopted pets. Method I followed is :


 App = {
 web3Provider: null,
 contracts: {},

init: function() {
// Load pets.
$.getJSON('../pets.json', function(data) {
  var petsRow = $('#petsRow');
  var petTemplate = $('#petTemplate');

  for (i = 0; i < data.length; i ++) {
    petTemplate.find('img').attr('src', data[i].picture);
    petTemplate.find('.btn-adopt').attr('data-id', data[i].id);


 return App.bindEvents();

 bindEvents: function() {
    $(document).on('click', '.btn-list', App.listAdopt); //Button in index.html for rendering to list.html page
    $(document).on('click', '.btn-listlist', App.listfun); //Button in list.html page for displaying adopted pets.
    $(document).on('click', '.btn-home', App.homepage);//Button in list.html for rendering to index.html

 homepage: function(){
    window.location.href ="../index.html";

 listAdopt: function(){
   window.location.href = "../list.html";

 listfun: function(adopters, account){

  //Code to display adopted pets in list.html


$(function() {
 $(window).load(function() {
 console.log('Inside window Load function');

So once it is redirected to 'list.html' it gives a blank page and on clicking a button will perform an event and display adopted pets.

When page is rendered to 'list.html', app.js is loaded again from App.init() since I have specified the script in 'list.html' and 'index.html'.I need same js file on each html page.

Is there any other way by which adopted pets could be displayed in 'list.html' once page is loaded.

1 Answer 1


I would add something on jquery document ready

 Your code

$( document ).ready(function() {
  • Thanks...Where I have place this code? I replaced $(document).on('click', '.btn-listlist', App.listfun); . But it doesn't work
    – angelmaria
    May 30, 2018 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.