title: jQuery not working properly in Laravel 5
body: <p>I have created a web application that takes input from a user, queries an API, processes the data with PHP and then presents it as a series of graphs using jQuery and D3.  I initially set this up in a procedural manner but have since been implementing it using the Laravel framework.  The problem I am having is that the JavaScript is not working properly in the final page; I think it has something to do with the way the Blade template system works.</p>
  
  <p>I know that it is accessing the JavaScript file correctly as it loads up the initial graphs.  However there is some extra functionality to reload the graphs according to different time spans and also to scroll through the data in the graphs.  After it has loaded the page, none of the jQuery stuff is working.</p>
  
  <p>Anyway, here is the code:</p>
  
  <p><strong>ROUTING:</strong> <code>routes.php</code> (app\Http)</p>
  
  <pre><code>&lt;?php
  
  // perform GET request on root and call method 'index' on the PagesController class
  // (app/Http/Controllers/PagesController.php)
  Route::get('/', 'PagesController@index');
  
  // perform POST on 'data' and call method 'process' on the PagesController class
  Route::post('data', 'PagesController@process');
  
  ?&gt;
  </code></pre>
  
  <p><strong>BASE TEMPLATE:</strong> <code>app.blade.php</code> (resources\views)</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  
  &lt;html lang="en"&gt;
  &lt;head&gt;
      {{-- this stops the default compatibility view for intranet sites in IE --}}
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" /&gt;
      &lt;title&gt;Academic Intelligence&lt;/title&gt;
  
      {{-- LINKS --}}
  
      {{-- local css file --}}
      {!! HTML::style('css/style.css') !!}
      {{-- bootstrap css (bootswatch readable style) --}}
      {!! HTML::style('//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/readable/bootstrap.min.css') !!}
      {{-- SCRIPTS --}}
      {{-- jquery --}}
      {!! HTML::script('https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js') !!}
      {{-- bootstrap js --}}
      {!! HTML::script('//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js') !!}
  &lt;/head&gt;
  &lt;body&gt;
      {{-- TITLE BAR --}}
      &lt;div class="sg-titlebar"&gt;
          &lt;h1&gt;&lt;a title="Newcastle University Homepage" accesskey="1" href="http://www.ncl.ac.uk/"/&gt;&lt;span title="Newcastle University"&gt;Newcastle University&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;
          &lt;h2&gt;&lt;a href="https://resviz.ncl.ac.uk/wos/"&gt;Academic Intelligence&lt;/a&gt;&lt;/h2&gt;
      &lt;/div&gt; 
      &lt;div class="sg-content"&gt;
          {{-- NAVIGATION BAR --}}
          &lt;nav class="navbar navbar-default" role="navigation"&gt;
              &lt;div class="container"&gt;
                  &lt;div class="navbar-header"&gt;
                  &lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&gt;
                      &lt;ul class="nav navbar-nav"&gt;
                          &lt;li&gt;&lt;a href="{{ action('PagesController@index') }}"&gt;&lt;span class="glyphicon glyphicon-home"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href="{{ action('PagesController@about') }}"&gt;About&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt; {{-- navbar-collapse --}}
              &lt;/div&gt; {{-- container --}}
          &lt;/nav&gt; {{-- navbar --}}
  
          {{-- main content --}}
          &lt;section class="container"&gt;
  
              {{-- unique section to other pages --}}
              @yield('content')
  
          &lt;/section&gt; {{-- main content; container --}}
      &lt;/div&gt; {{-- sg-content --}}
  
      {{-- FOOTER --}}
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>HOME PAGE:</strong> <code>home.blade.php</code> (resources\views\pages)</p>
  
  <pre><code>{{-- this HTML is inserted into app.blade.php as content --}}
  @extends('app')
  
  @section('content')
  
  {{-- local script --}}
  {!! HTML::script('js/script.js') !!}
  
  &lt;div class="row"&gt;
      {{-- search form --}}
      {{-- using Illuminate\Html\HtmlServiceProvider package --}}
      {!! Form::open(['url' =&gt; 'data', 'id' =&gt; 'form']) !!}
          &lt;fieldset&gt;
              &lt;div class="form-group"&gt;
                  {{-- see http://getbootstrap.com/css/#grid for explanation of Bootstrap grid system --}}
                  &lt;div class="col-lg-6 well bs-component"&gt;
                      {{-- 'journal(s) section of form' --}}
                      &lt;div class="journal_fields_wrap"&gt;
                          {{-- 'journal(s)' section header --}}
                          &lt;h4 class="form_title"&gt;Journal&lt;/h4&gt;
                          {{-- buttons above 'journal(s)' input boxes --}}
                          &lt;div class="journal_buttons"&gt;
                              {{-- loads a list of journals on Web of Science --}}
                              &lt;a class="btn btn-success" target="_blank" href="http://ip-science.thomsonreuters.com/cgi-bin/jrnlst/jloptions.cgi?PC=D"
                              data-toggle="tooltip-down" title="Search Thomson Reuters for journals"&gt;Journal List&lt;/a&gt;
                              {{-- add extra input field for journals --}}
                              {!! Form::button('&lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;    Add more fields', ['class' =&gt; 'add_journal_field_button btn btn-info']) !!}
                          &lt;/div&gt; {{-- journal_buttons --}}
                          {{-- input box for journal(s) --}}
                          &lt;div class="form_field"&gt;
                              {{-- parameters: textbox(name, default value, options array) --}}
                              {!! Form::text('journal1', null, ['class' =&gt; 'form-control', 'data-toggle' =&gt; 'tooltip-right', 'title' =&gt; 'Please enter only one journal per box']) !!}
                          &lt;/div&gt; {{-- form_field --}}
                      &lt;/div&gt; {{-- journal_fields_wrap --}}
  
                      {{-- 'keyword(s)' section of form --}}
                      &lt;div class="title_fields_wrap"&gt;
                          {{-- 'keyword(s)' section header --}}
                          &lt;h4 class="form_title"&gt;Keyword&lt;/h4&gt;
                          {{-- buttons above 'keyword(s)' input boxes --}}
                          &lt;div class="title_buttons"&gt;
                              {{-- add extra input field for keywords --}}
                              {!! Form::button('&lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;    Add more fields', ['class' =&gt; 'add_title_field_button btn btn-info']) !!}
                          &lt;/div&gt; {{-- title_buttons --}}
                          {{-- input box for keyword(s) --}}
                          &lt;div class="form_field"&gt;
                              {{-- parameters: textbox(name, default value, options array) --}}
                              {!! Form::text('title1', null, ['class' =&gt; 'form-control', 'data-toggle' =&gt; 'tooltip-right', 'title' =&gt; 'Please enter only one title per box']) !!}
                          &lt;/div&gt; {{-- form_field --}}
                      &lt;/div&gt; {{-- title_fields_wrap --}}
  
                      {{-- 'time span' section of form; header --}}
                      &lt;h4 class="form_title"&gt;Time Span&lt;/h4&gt;&lt;/br&gt;
                      {{-- 'From:' header --}}
                      {!! Form::label('select', 'From:', ['class' =&gt; 'col-lg-2 control-label']) !!}
                      &lt;div class="col-lg-3"&gt;
                          {{-- parameters: selectbox(name, [data], default, [options]) --}}
                          {{-- data (years) provided by script.js --}}
                          {!! Form::select('timeStart', [], 'Select', ['class' =&gt; 'form-control', 'id' =&gt; 'select']) !!}
                      &lt;/div&gt; {{-- col-lg-3 --}}
                      {{-- 'To:' header --}}
                      {!! Form::label('select', 'To:', ['class' =&gt; 'col-lg-2 control-label']) !!}
                      &lt;div class="col-lg-3"&gt;
                          {{-- as other select box above --}}
                          {!! Form::select('timeEnd', [], 'Select', ['class' =&gt; 'form-control', 'id' =&gt; 'select']) !!}
                      &lt;/div&gt; {{-- col-lg-3 --}
                      &lt;br/&gt;&lt;br/&gt;
  
                      {{-- execute search; submit button --}}
                      {{-- parameters: button(text on button, [options]) --}}
                      {!! Form::button('&lt;strong&gt;Submit&lt;/strong&gt;&lt;span class="glyphicon glyphicon-transfer"&gt;&lt;/span&gt;', ['type' =&gt; 'submit', 'class' =&gt; 'btn btn-primary btn-lg', 'id' =&gt; 'submit']) !!}
  
                  &lt;/div&gt; {{-- col-lg-6 --}}
  
                  &lt;div class="col-lg-6 well bs-component"&gt;
                      {{-- bootstrap window --}}
                      &lt;div class="modal-dialog"&gt;
                          &lt;h4&gt;Notes&lt;/h4&gt;
                          &lt;p&gt;This application is optimised for Chrome.&lt;/p&gt;
                          &lt;p&gt;In order to get the best results from your search,&lt;br/&gt;enter one or more journals.&lt;/p&gt;
                          &lt;p&gt;Keywords and time spans are optional but can be&lt;br/&gt;used to refine your search.&lt;/p&gt;
                      &lt;/div&gt; {{-- modal-dialog --}}
  
                  &lt;/div&gt; {{-- col-lg-6 --}}
  
              &lt;/div&gt; {{-- form-group --}}
          &lt;/fieldset&gt;
      {!! Form::close() !!}
  &lt;/div&gt; {{-- row --}}
  
  @stop
  </code></pre>
  
  <p><strong>DATA DISPLAY:</strong> <code>data.blade.php</code> (resources\views\pages)</p>
  
  <pre><code>@extends('app')
  
  @section('content')
  
  &lt;!-- d3 --&gt;
  {!! HTML::script('https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js') !!}
  &lt;!-- local script --&gt;
  {!! HTML::script('js/graphs.js') !!}
  
  &lt;section class="graphs container"&gt;
  
  &lt;div class="row col-lg-12" id="header"&gt;
      &lt;div class="col-lg-1"&gt;&lt;/div&gt;
      &lt;div class="panel panel-info col-lg-7"&gt;
          &lt;div class="panel-heading"&gt;
              &lt;h2 class="panel-title"&gt;Search Parameters&lt;/h2&gt;
          &lt;/div&gt;
          &lt;div class="panel-body"&gt;
              &lt;div id="journalData"&gt;&lt;/div&gt;
              &lt;div id="keywordData"&gt;&lt;/div&gt;
              &lt;div id="timescaleData"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt; &lt;!-- panel panel-info --&gt;
  
      &lt;div class="dropdown col-lg-2"&gt;
          &lt;div class="form-group"&gt;
              &lt;label for="select" class="control-label"&gt;Change time span:&lt;/label&gt;
              &lt;select class="form-control" id="timeSelect"&gt;
                  &lt;option value="chart2" selected&gt;User defined&lt;/option&gt;
                  &lt;option value="chart4"&gt;Last 10 years&lt;/option&gt;
                  &lt;option value="chart5"&gt;Last 5 years&lt;/option&gt;
                  &lt;option value="chart6"&gt;Last 2 years&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
      &lt;/div&gt; &lt;!-- dropdown --&gt;
      &lt;div class="col-lg-2"&gt;&lt;/div&gt;
  &lt;/div&gt; &lt;!-- row --&gt;
  
  &lt;div class="graph_fields_wrap row backdrop col-lg-12"&gt;
          &lt;div class="col-lg-6"&gt;
              &lt;h3 class="titles"&gt;Ranked Author Citations&lt;/h3&gt;
              &lt;h4 class="titles"&gt;All time (from 1970)&lt;/h4&gt;
              &lt;button class="pager" id="previous1" type="button" disabled&gt;&lt;span class="glyphicon glyphicon-chevron-left"&gt;&lt;/span&gt; previous&lt;/button&gt;
              &lt;button class="pager indexer" type="button" disabled&gt;1 - 10&lt;/button&gt;
              &lt;button class="pager" id="next1" type="button"&gt;next &lt;span class="glyphicon glyphicon-chevron-right"&gt;&lt;/span&gt;&lt;/button&gt;
              &lt;div class="chart1 well bs-component"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col-lg-6"&gt;
              &lt;h3 class="titles"&gt;Ranked Author Citations&lt;/h3&gt;
              &lt;h4 class="titles" id="userTitle"&gt;&lt;/h4&gt;
              &lt;button class="pager" id="previous2" type="button" disabled&gt;&lt;span class="glyphicon glyphicon-chevron-left"&gt;&lt;/span&gt; previous&lt;/button&gt;
              &lt;button class="pager indexer" type="button" disabled&gt;1 - 10&lt;/button&gt;
              &lt;button class="pager" id="next2" type="button"&gt;next &lt;span class="glyphicon glyphicon-chevron-right"&gt;&lt;/span&gt;&lt;/button&gt;
              &lt;div class="chart2 well bs-component"&gt;&lt;/div&gt;
          &lt;/div&gt;
  &lt;/div&gt; &lt;!-- row --&gt;
  
  &lt;/br&gt;
  
  &lt;div class="row col-lg-12"&gt;
      &lt;div class="row backdrop col-lg-7" id="impact"&gt;
          &lt;h3 class="titles"&gt;Weighted Citation Factor&lt;/h3&gt;
          &lt;h4 class="titles"&gt;All time (from 1970)&lt;/h4&gt;
          &lt;div class="well bs-component" id="rankChart"&gt;
              &lt;div class="chart3"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt; &lt;!-- row --&gt;
      &lt;div class="backdrop col-lg-5" id="algorithm"&gt;
          &lt;h3 class="titles"&gt;Explanation of Bubble Chart&lt;/h3&gt;
          &lt;div class="well bs-component"&gt;
              &lt;p&gt;The weighted citation factor applies a weighting to citations based on the year of publication. The more recent the citation, the higher the weighting.&lt;/p&gt;
              &lt;p&gt;This chart takes into account data from all years.  The higher the weighted citation factor, the larger the bubble.&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; &lt;!-- col-lg-12 --&gt;
  
  &lt;/br&gt;
  
  &lt;div class="graph_fields_wrap2 row backdrop col-lg-12"&gt;
      &lt;div class="col-lg-6"&gt;
          &lt;h3 class="titles"&gt;Ranked Awarded Funds (£millions)&lt;/h3&gt;
          &lt;h4 class="titles"&gt;All time, UK only&lt;/h4&gt;
          &lt;div class="chart7 well bs-component"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="col-lg-6"&gt;
          &lt;h3 class="titles"&gt;Ranked Awarded Funds (£millions)&lt;/h3&gt;
          &lt;h4 class="titles userTitle"&gt;, UK only&lt;/h4&gt;
          &lt;div class="chart8 well bs-component"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; &lt;!-- row --&gt;
  &lt;/section&gt;
  
  @stop
  </code></pre>
  
  <p><strong>PHP PROCESSING:</strong> <code>PagesController.php</code> (app\Http\Controllers)</p>
  
  <pre><code>&lt;?php namespace App\Http\Controllers;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use Request;
  use App\SoapController;
  use App\Models\SearchData;
  use App\Models\SoapWrapper;
  use App\Models\RestWrapper;
  use App\Models\DataSort;
  use App\Models\BubbleChartCompatible;
  use DB;
  use View;
  use Laracasts\Utilities\JavaScript\JavaScriptFacade as JavaScript;
  
  class PagesController extends Controller {
  
  public function __construct()
  {
      $this-&gt;middleware('guest');
  }
  
  // method index returns view 'home' (resources/views/home.blade.php)
  public function index()
  {
      return view('pages.home');
  }
  
  // method process returns view 'data' (resources/views/data.blade.php)
  public function process()
  {
      ... processes data ...
  
      // pass data to JavaScript (uses https://github.com/laracasts/PHP-Vars-To-Js-Transformer)
      JavaScript::put([
                          'allCited' =&gt; $allCited,
                          'userCited' =&gt; $userCited,
                          'tenCited' =&gt; $tenCited,
                          'fiveCited' =&gt; $fiveCited,
                          'twoCited' =&gt; $twoCited,
                          'valueData' =&gt; $valueData,
                          'allFunded' =&gt; $allFunds,
                          'userFunded' =&gt; $userFunds,
                          'tenFunded' =&gt; $tenFunds,
                          'fiveFunded' =&gt; $fiveFunds,
                          'twoFunded' =&gt; $twoFunds,
                          'searchData' =&gt; $searchParams
                      ]);
  
      return View::make('pages.data');
  }
  }
  </code></pre>
  
  <p><strong>JAVASCRIPT:</strong> <code>graphs.js</code> (public\js)</p>
  
  <pre><code>$(document).ready(function() {
  
  // pull data from PHP
  // CITES
  var allCitedData = $.parseJSON(Graphs.allCited);
  var userCitedData = $.parseJSON(Graphs.userCited);
  var tenCitedData = $.parseJSON(Graphs.tenCited);
  var fiveCitedData = $.parseJSON(Graphs.fiveCited);
  var twoCitedData = $.parseJSON(Graphs.twoCited);
  // VALUES; leave in JSON format
  var valueData = Graphs.valueData;
  // FUNDS
  var allFundedData = $.parseJSON(Graphs.allFunded);
  var userFundedData = $.parseJSON(Graphs.userFunded);
  var tenFundedData = $.parseJSON(Graphs.tenFunded);
  var fiveFundedData = $.parseJSON(Graphs.fiveFunded);
  var twoFundedData = $.parseJSON(Graphs.twoFunded);
  // USER SEARCH PARAMETERS
  var searchData = Graphs.searchData;
  
  // different colour settings for graphs
  var palette1 = {
      fill: "steelblue",
      hover: "brown"
  };
  
  var palette2 = {
      fill: "seagreen",
      hover: "darkorange"
  };
  
  var palette3 = {
      fill: "darkblue",
      hover: "darkmagenta"
  };
  
  var palette4 = {
      fill: "darkolivegreen",
      hover: "darkseagreen"
  };
  
  // set title for user defined graph
  var graphTitle = $(".userTitle");
  console.log(searchData.from + " to " + searchData.to);
  graphTitle.prepend(searchData.from + " to " + searchData.to);
  
  // change graph according to dropdown choice
  var wrapperG = $(".graph_fields_wrap1"); // wrapper for div containing citations graphs
  var wrapperF = $(".graph_fields_wrap2"); // wrapper for div containing funds graphs
  var selector = $("#timeSelect"); // dropdown graph menu ID
  // variables to log subset location in arrays (to use in slice)
  var from1 = 0;
  var to1 = 10;
  var from2 = 0;
  var to2 = 10;
  var from3 = 0;
  var to3 = 10;
  var from4 = 0;
  var to4 = 10;
  var from5 = 0;
  var to5 = 10;
  var selected = "chart2";
  
  // when the selection is changed in the dropdown menu do:
  selector.on("change", function(e) {
      // ignore default action for this event
      e.preventDefault();
      // remove currently displayed graph, 1st child of div (1st graph is 0th)
      $(wrapperG.children()[1]).remove();
      $(wrapperF.children()[1]).remove();
      // get value of currently selected
      var selectedVal = $(this).val();
      selected = selectedVal;
      // check value of selected
      // append new graph to wrapper div &amp; run loadGraph to reprocess data
      if (selectedVal == "chart2") {
          wrapperG.append("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;" + searchData.from + " to " + searchData.to + "&lt;/h4&gt;&lt;button class='pager' id='previous2' type='button' disabled&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;1-10&lt;/button&gt;&lt;button class='pager' id='next2' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart2 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph(userCitedData.slice(0,10), selectedVal, palette2);
          wrapperF.append("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Awarded Funds (£millions)&lt;/h3&gt;&lt;h4 class='titles'&gt;" + searchData.from + " to " + searchData.to + ", UK only&lt;/h4&gt;&lt;div class='chart8 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph(userFundedData.slice(0,10), "chart8", palette4);
      } else if 
         ... etc ...
  
  });
  
  /*****************************************/
  /***********  PAGINATION *****************/
  /*****************************************/
  // ALL TIME CITED, chart1
  // next author set
  wrapperG.on("click", "#next1", function (e) {
      // ignore default action for this event
      e.preventDefault();
      // shift pointers up 10 for next subset of array
      from1 += 10;
      to1 += 10;
      // check if at end of data
      if (to1 &gt; (allCitedData.length)) {
          // remove currently displayed graph, 0th child of div
          $(wrapperG.children()[0]).remove();
          // load new graph before other graph (0th child of div)
          wrapperG.prepend("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;All time (from 1970)&lt;/h4&gt;&lt;button class='pager' id='previous1' type='button'&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from1+1) + " - " + to1 + "&lt;/button&gt;&lt;button class='pager' id='next1' type='button' disabled&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart1 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((allCitedData.slice(from1,to1)), "chart1", palette1);
      } else {
          // remove currently displayed graph, 0th child of div
          $(wrapperG.children()[0]).remove();
          // load new graph before other graph (0th child of div)
          wrapperG.prepend("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;All time (from 1970)&lt;/h4&gt;&lt;button class='pager' id='previous1' type='button'&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from1+1) + " - " + to1 + "&lt;/button&gt;&lt;button class='pager' id='next1' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart1 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((allCitedData.slice(from1,to1)), "chart1", palette1);
      }
  });
  
  // all time cited, previous author set
  wrapperG.on("click", "#previous1", function (e) {
      // ignore default action for this event
      e.preventDefault();
      // shift pointers down 10 for previous subset of array
      from1 -= 10;
      to1 -= 10;
      // check if at start of data
      if (from1 == 0) {
          // remove currently displayed graph, 0th child of div
          $(wrapperG.children()[0]).remove();
          // load new graph before other graph (0th child of div)
          wrapperG.prepend("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;All time (from 1970)&lt;/h4&gt;&lt;button class='pager' id='previous1' type='button' disabled&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from1+1) + " - " + to1 + "&lt;/button&gt;&lt;button class='pager' id='next1' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart1 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((allCitedData.slice(from1,to1)), "chart1", palette1);
      } else {
          // remove currently displayed graph, 0th child of div
          $(wrapperG.children()[0]).remove();
          // load new graph before other graph (0th child of div)
          wrapperG.prepend("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;All time (from 1970)&lt;/h4&gt;&lt;button class='pager' id='previous1' type='button'&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from1+1) + " - " + to1 + "&lt;/button&gt;&lt;button class='pager' id='next1' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart1 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((allCitedData.slice(from1,to1)), "chart1", palette1);
      }
  });
  
  // OPTIONS CITED, charts 2, 4, 5 &amp; 6
  // optional cited, next author set
  wrapperG.on("click", "#next2", function (e) {
      // ignore default action for this event
      e.preventDefault();
      // remove currently displayed graph, 1st child of div (1st graph is 0th)
      $(wrapperG.children()[1]).remove();
      // check selectedVal to see which graph to append
      switch(selected) {
          case ("chart2"):
              // shift pointers up 10 for next subset of array
              from2 += 10;
              to2 += 10;
              // check if at end of data
              if (to2 &gt;= (userCitedData.length)) {
                  // load new graph after other graph (1st child of div)
                  wrapperG.append("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;" + searchData.from + " to " + searchData.to + "&lt;/h4&gt;&lt;button class='pager' id='previous2' type='button'&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from2+1) + " - " + to2 + "&lt;/button&gt;&lt;button class='pager' id='next2' type='button' disabled&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart2 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((userCitedData.slice(from2,to2)), "chart2", palette2);
              } else {
                  wrapperG.append("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;" + searchData.from + " to " + searchData.to + "&lt;/h4&gt;&lt;button class='pager' id='previous2' type='button'&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from2+1) + " - " + to2 + "&lt;/button&gt;&lt;button class='pager' id='next2' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart2 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((userCitedData.slice(from2,to2)), "chart2", palette2);
              }
              break;
          ... etc ...
      }
  });
  
  // optional cited, previous author set
  wrapperG.on("click", "#previous2", function (e) {
      // ignore default action for this event
      e.preventDefault();
      // remove currently displayed graph, 1st child of div (1st graph is 0th)
      $(wrapperG.children()[1]).remove();
      // check selectedVal to see which graph to append
      switch(selected) {
          case ("chart2"):
              // shift pointers down 10 for previous subset of array
              from2 -= 10;
              to2 -= 10;
              // check if at start of data
              if (from2 == 0) {
                  // load new graph after other graph (1st child of div)
                  wrapperG.append("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;" + searchData.from + " to " + searchData.to + "&lt;/h4&gt;&lt;button class='pager' id='previous2' type='button' disabled&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from2+1) + " - " + to2 + "&lt;/button&gt;&lt;button class='pager' id='next2' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart2 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((userCitedData.slice(from2,to2)), "chart2", palette2);
              } else {
                  wrapperG.append("&lt;div class='col-lg-6'&gt;&lt;h3 class='titles'&gt;Ranked Author Citations&lt;/h3&gt;&lt;h4 class='titles'&gt;" + searchData.from + " to " + searchData.to + "&lt;/h4&gt;&lt;button class='pager' id='previous2' type='button'&gt;&lt;span class='glyphicon glyphicon-chevron-left'&gt;&lt;/span&gt; previous&lt;/button&gt;&lt;button class='pager indexer' type='button' disabled&gt;" + (from2+1) + " - " + to2 + "&lt;/button&gt;&lt;button class='pager' id='next2' type='button'&gt;next &lt;span class='glyphicon glyphicon-chevron-right'&gt;&lt;/span&gt;&lt;/button&gt;&lt;div class='chart2 well bs-component'&gt;&lt;/div&gt;&lt;/div&gt;").loadGraph((userCitedData.slice(from2,to2)), "chart2", palette2);
              }
              break;
          case ("chart4"):
              ... etc ...
      }
  });
  
  // create array to store various chart names
  var fundedCharts = [
                        "chart7",
                        "chart8",
                        "chart9",
                        "chart10",
                        "chart11"
                    ];
  
  // Immediately Invoked Function Expression: allows '$' to work with any other plugins
  (function ($) {
      // add function to '$.fn' object (contains all jQuery object methods)
      $.fn.loadGraph = function(graphData, graphSelect, graphColour) {
          ... creates graph from data ...
  } (jQuery));
  
  // bubble chart
  (function ($) {
      $.fn.loadBubbles = function(graphData, graphSelect) {
          ... creates bubble chart from data ...
  } (jQuery));
  
  // load initial graphs to page, 1st 10 authors
  $(".chart1").loadGraph(allCitedData.slice(0,10), "chart1", palette1);
  $(".chart2").loadGraph(userCitedData.slice(0,10), "chart2", palette2);
  $(".chart3").loadBubbles(valueData, "chart3");
  $(".chart7").loadGraph(allFundedData.slice(0,10), "chart7", palette3);
  $(".chart8").loadGraph(userFundedData.slice(0,10), "chart8", palette4);
  
  });
  </code></pre>
  
  <p>I went over my char limit so had to cut out some of the code but I think I've left what's important to identify the problem.</p>
  
  <p>Basically it loads the page with the graphs fine, but if you try to load new graphs with the <code>#timeSelect</code> dropdown or scroll through the data with <code>#next1</code>, nothing happens.</p>
  
  <p>Let me know if you need any more info - thanks.</p>
  
  <p>** <strong>ADDITIONAL INFO</strong> **</p>
  
  <p>I used <a href="https://github.com/laracasts/PHP-Vars-To-Js-Transformer">https://github.com/laracasts/PHP-Vars-To-Js-Transformer</a> in order to get my data to the view to load the graphs.  When you use this it publishes a file to <code>config</code> called <code>javascript.js</code>.  I have changed this to accommodate my app, but this could be where I'm going wrong.  This is my amended file:</p>
  
  <p><code>javascript.php</code> (config)</p>
  
  <pre><code>return [
      'bind_js_vars_to_this_view' =&gt; 'pages.data',
  
      'js_namespace' =&gt; 'Graphs'
  ];
  </code></pre>