Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  173] [ 6]  / answers: 1 / hits: 37467  / 12 Years ago, thu, november 1, 2012, 12:00:00

Referring to this example:



http://vallandingham.me/stepper_steps.html



it seems that the D3 and jQuery libraries are very similar in the sense that they both do DOM manipulation in an object-chaining way.



I'm curious as to know what functions D3 makes easier than jQuery and vice versa. There are plenty of graphing and visualization libraries that use jQuery as a basis (e.g., , , ).



Please give specific examples of how they are different.


More From » jquery

 Answers
8

  • D3 is data-driven but jQuery is not: with jQuery you directly manipulate elements, but with D3 you provide data and callbacks through D3's unique data(), enter() and exit() methods and D3 manipulates elements.


  • D3 is usually used for data visualization but jQuery is used for creating web apps. D3 has many data visualization extensions and jQuery has many web app plugins.


  • Both are JavaScript DOM manipulation libraries, have CSS selectors and fluent API and are based on web standards which makes them look similar.




Following code is an example of D3 usage which is not possible with jQuery (try it in jsfiddle):



  // create selection
var selection = d3.select('body').selectAll('div');

// create binding between selection and data
var binding = selection.data([50, 100, 150]);

// update existing nodes
binding
.style('width', function(d) { return d + 'px'; });

// create nodes for new data
binding.enter()
.append('div')
.style('width', function(d) { return d + 'px'; });

// remove nodes for discarded data
binding.exit()
.remove();

[#82240] Wednesday, October 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinisaaka

Total Points: 194
Total Questions: 105
Total Answers: 104

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;