1

I'm creating a Java Script widget for the site based on CodeIgniter. The site using templates and Blade library. I need to load my java script right after the page has been loaded. I have added it into template scripts.blade.php:

<script src="{{apps_url('assets/my_widget/js/my_widget.js')}}"></script>

Unfortunately, it seems, what my script was executed before controller has been loaded and therefore the script can not find required SVG object:

(function() {
  var container = d3.select(".myContainer");

  alert("container: " + container);

})();

This alert show what container is null even if the myContainer object actually exists on the page and was recognized by CSS. The d3 library has been loaded properly and there is no errors in the Firefox console.

Is there a way to execute this script right after the object has been loaded?

Dmitry
  • 1,791
  • 3
  • 13
  • 21

1 Answers1

0

use

$(document).ready(function() {
(function() {
  var container = d3.select(".myContainer");

  alert("container: " + container);

})();
  });
Visakh B Sujathan
  • 257
  • 1
  • 4
  • 24