Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .ready() equivalent in d3js?

currently i am adding all javascript at HTML <head> after uglying as file & using these jquery functions to check document ready

$( document ).ready(function() {}); OR $(function() {});

is there any d3js equivalent to remove using of these jquery functions ?

like image 209
linto cheeran Avatar asked Dec 26 '15 08:12

linto cheeran


People also ask

What is ready method in jQuery?

The ready() method is an inbuilt method in jQuery which helps to load the whole page then execute the rest code. This method specify the function to execute when the DOM is fully loaded. Syntax: $(document).ready(function) Parameters: This method accepts single parameter function which is mandatory.

What is JavaScript equivalent of document ready?

Answer: Use the DOMContentLoaded Event You can utilize the JavaScript Window's DOMContentLoaded event to construct $(document). ready() equivalent without jQuery.

Is it necessary to use document ready in jQuery?

A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.


2 Answers

A

You can simply put the <script> tag at the bottom of the body tag.

B

you can add the DOMContentLoaded event and insert your d3js code inside.

document.addEventListener("DOMContentLoaded", function(e) {
   /* Your D3.js here */
  });

Direct Answer

There is no equivalent to the jQuery function in the D3.js library, the snippet written above will work as well.

like image 133
Hulke Avatar answered Oct 21 '22 12:10

Hulke


There is no specific d3 way but,

if your javascript is below any of the html elements then the dom is loaded before it starts executing the javascript.

Putting your javascript at the bottom of the body is usually good enough. You can also use native js method which works in most of the browsers.

document.addEventListener("DOMContentLoaded", function(event) { 
  //do work
});
like image 44
Fawzan Avatar answered Oct 21 '22 14:10

Fawzan