Is the HTML shown via 'View Source' different from the HTML shown in (Firebug) developer tools?

18,976

Solution 1

Yes they are different.

View source shows you the original HTML source of the page.

The inspector shows you the DOM as it was interpreted by the browser. This includes for example changes made by javascript which cannot be seen in the HTML source.

Oh and this also counts for the developer tools that allow you to view the DOM in other browsers, like the Chrome Web Inspector and Internet Explorer Developer Toolbar. The HTML source will always be the same across all browsers, the generated DOM might differ as it is an interpretation and render engines are not all the same (unfortunately).

Solution 2

It should also be noted that aside from the dynamic DOM manipulation which could be occurring via javascript etc, Firefox will also parse and "clean-up" malformed (X)HTML, so these changes will also affect what you see when inspecting an element.

Solution 3

In Firefox, View Source may reload the page, changing what is on it. See this bug and vote for it if it is bothering you:

https://bugzilla.mozilla.org/show_bug.cgi?id=307089

Solution 4

The difference are (but not limited to) that in firebug console you can see dynamically changes, which occurred in web page. For example, DOM elements modifications (from AJAX or regular JavaScript), CSS in-place modifications, etc...

Share:
18,976

Related videos on Youtube

sergserg
Author by

sergserg

sergserg

Updated on June 05, 2022

Comments

  • sergserg
    sergserg almost 2 years

    I'm using Firefox alongside Firebug Developer tools.

    Is the HTML shown in View Source (Ctrl + U) different from the HTML I see when inspecting elements using Firebug?

    What are the differences between the two?

  • jakub.g
    jakub.g over 11 years
    I'll add 2 cents about one tricky thing. Firebug and other dev tools will show the modified source code, but only by changes done through JavaScript. They won't reflect some changes on the page that were performed due to your interaction with the page handled natively by the browser. Example: let's say you have <input type="text" value="foo" />. When you click the text field and modify the value to bar, it'll remain foo both in CTRL-U source view and in dev tools like Firebug.
  • T.J. Crowder
    T.J. Crowder almost 8 years
    @jakub.g: That's because the current value of an input is not held in the value attribute. It's held in the value property. The value attribute holds the default value of the input (you can access it through its reflected property, defaultValue -- and if you change defaultValue, you'll see that change in the value attribute in dev tools). jsfiddle.net/jzh6b3fc
  • Leandro
    Leandro almost 6 years
    Can we get the interpreted DOM programmatically from Python or Php?
  • Rik
    Rik almost 6 years
    @Leandro You could if you send the innerHTML to the backend, or if you have some sort of module that generates a DOM on the backend.