Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
112
rated 0 times [  114] [ 2]  / answers: 1 / hits: 80090  / 11 Years ago, sun, may 12, 2013, 12:00:00

I'm a bit puzzled by the following: Let's say I've got a paragraph element with the id of para. Using Chromes console, if I say



document.getElementById(para)


I'm returned with the HTML snippet <p id=para>....</p>, whereas if I use for instance the Javascript library D3's selection method and say



d3.select(#para)


I'm returned with the DOM node and can access all the properties and methods of the paragraph element.



Why this difference?


More From » dom

 Answers
16

By default, when logging a DOM node in Chrome, it displays as markup. To log the DOM node as a normal object use console.dir. The reason d3.select(#para) shows as a normal object is that this method probably doesn't return a DOM node, but an object that wraps over the DOM node.



console.dir(document.getElementById(para));

[#78278] Friday, May 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ariel

Total Points: 523
Total Questions: 111
Total Answers: 100

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;