Reputation: 27
I want to understand the basic difference between the following statements. Id is targeting a checkbox tag.
1] Var loc = document.getElementById("location");
Console.log(loc);
2] console.log(document.getElementById("location"));
Ist one writes [object HTMLInputElement] 2nd writes the html code for the checkbox tag
Upvotes: 1
Views: 34
Reputation: 27
Document.getelementbyid("loc").onclickworks but the this in a variable wont work and i think its not about browser and the var in console works if we save the textbox in a variable and push it to the console
Upvotes: 0
Reputation: 1896
1). You declare a variable and saves the html element as an object in loc, then you write to the console.
2). You write pure the html element object directly to the console.
There is no difference in the value that you write out to the console.
Upvotes: 1
Reputation: 1074038
Your statements are identical in any real sense (other than the variable), it's just how console
has displayed the result.
The console behaves differently (at least in Chrome) depending on whether it's open when you log something. My guess is that you had it closed for your first example but open for your second (or similar).
But it's about the console, not the DOM. In both cases, what you were passing to console.log
was a reference to an HTML element.
Upvotes: 2