Return to Video

Introduction to the DOM Inspector

  • 0:00 - 0:03
    In this video we're going to learn about the DOM Inspector.
  • 0:03 - 0:05
    And we're going to learn how to use it for Firefox development.
  • 0:05 - 0:10
    DOM stands for Document Object Model
  • 0:10 - 0:15
    And it's basically just an in memory representation, it's a tree structure, of a web page or XML document.
  • 0:15 - 0:19
    It also provides an API to work with that in memory representation.
  • 0:19 - 0:24
    You might have guessed but the DOM Inspector allows you to basically inspect the DOM.
  • 0:24 - 0:28
    You can also do a lot of things like manipulate it as well.
  • 0:28 - 0:32
    At the time of this video, there's actually a built in Firefox tool called the Inspector.
  • 0:32 - 0:38
    I'm just going to show you how that works, you can right click for example on anything on a web page.
  • 0:38 - 0:40
    And you can select Inspect Element
  • 0:40 - 0:43
    And that'll bring in the inspector right there.
  • 0:43 - 0:47
    And this shows you the in memory representation of the web page.
  • 0:47 - 0:51
    And you can expand it for example, you can see things there.
  • 0:51 - 0:59
    You can even for example double click on the text, and change it... there you go.
  • 0:59 - 1:02
    You can see that it updates live right there.
  • 1:02 - 1:07
    But this inspector tool can't be used for Firefox development.
  • 1:07 - 1:12
    So what we're going to use instead is use the tool that was built before this Inspector tool was available.
  • 1:12 - 1:14
    Called the DOM Inspector.
  • 1:14 - 1:15
    And it's an extension.
  • 1:15 - 1:20
    So to install that extension, I'm just going to type inside here.
  • 1:20 - 1:27
    DOM Inspector Firefox extension, hit enter.
  • 1:27 - 1:32
    And I can actually close the Inspector now.
  • 1:32 - 1:35
    And you'll see it right here as the first result.
  • 1:35 - 1:37
    I'm going to click that.
  • 1:37 - 1:41
    And I'm just going to click on Add to Firefox.
  • 1:41 - 1:48
    And click on Install Now.
  • 1:48 - 1:54
    And this extension needs to be restarted so I'm going to click on Restart Now.
  • 1:54 - 2:00
    Alright we're back there now.
  • 2:00 - 2:04
    Now to access it, I can just hold down the Alt key.
  • 2:04 - 2:09
    Go to the Tools menu here, Web Developer.
  • 2:09 - 2:10
    And go to DOM Inspector.
  • 2:10 - 2:15
    And it brings up this second window right here.
  • 2:15 - 2:23
    Now you can use this DOM Inspector for both modifying content and Firefox development.
  • 2:23 - 2:30
    But I only recommend to use it for Firefox development, and I recommend to use the built in Inspector tool for content.
  • 2:30 - 2:34
    So we're just going to go through the menus here.
  • 2:34 - 2:39
    In the File menu, if you go to Inspect, you can see that it says Inspect a Content Document,
  • 2:39 - 2:43
    and that shows the currently loaded content documents that I have.
  • 2:43 - 2:45
    Or you can Inspect a chrome document.
  • 2:45 - 2:48
    And that's basically Firefox itself.
  • 2:48 - 2:53
    So I'm just going to go to the first item here.
  • 2:53 - 2:55
    Inspect Firefox window itself.
  • 2:55 - 3:03
    And you can see that it's loading up the browser/content/browser.xul
  • 3:03 - 3:07
    And that's the XUL document for the main window itself.
  • 3:07 - 3:12
    Again you can see that there's different stylesheets here, I can actually click on them.
  • 3:12 - 3:15
    And if I wanted to I could actually: delete, delete, delete...
  • 3:15 - 3:18
    You can see the style being removed in the background window right there.
  • 3:18 - 3:19
    As I do that.
  • 3:19 - 3:22
    And I can also Undo to get them back.
  • 3:22 - 3:26
    You can look through the actual DOM as well.
  • 3:26 - 3:30
    So I'm expanding window, it shows that there is a bunch of scripts there.
  • 3:30 - 3:33
    And each of these things you can click on, you can delete, or you can modify.
  • 3:33 - 3:40
    Now a handy feature of the DOM Inspector is this little click to find element feature.
  • 3:40 - 3:44
    So for example in past videos, we modified the URL bar to have a red color.
  • 3:44 - 3:49
    How I found the ID of that URL bar, is by clicking this button right here.
  • 3:49 - 3:52
    Find a node, inspect by clicking it.
  • 3:52 - 3:58
    And then you go ahead and select the thing that you're interested in finding out the ID of.
  • 3:58 - 4:00
    So I'm going to click on the URL bar right there.
  • 4:00 - 4:05
    And it selected red for a second.
  • 4:05 - 4:07
    I'm going to go back to this.
  • 4:07 - 4:12
    Now it found this item down here, urlbar. Usually it'll have some red things.
  • 4:12 - 4:15
    Usually you want the parent of the red thing.
  • 4:15 - 4:18
    The red is an anonymous content node, and we'll get into that later.
  • 4:18 - 4:21
    But you usually want the first parent above the red stuff.
  • 4:21 - 4:28
    So you can see that the ID column right here, shows that the ID of the text box right there is the URL bar.
  • 4:28 - 4:30
    And that flashing red is not something that I added with the video.
  • 4:30 - 4:32
    It's actually part of the DOM Inspector itself.
  • 4:32 - 4:37
    So on the right here, you can see the DOM object node.
  • 4:37 - 4:39
    ... for the text box URL bar.
  • 4:39 - 4:41
    And you can see all the properties of it.
  • 4:41 - 4:47
    Like the ID, the flex, the type, etc.
  • 4:47 - 4:49
    Any attribute of that DOM element will show up there.
  • 4:49 - 4:55
    You can also go ahead and double click an item.
  • 4:55 - 4:58
    And you can actually modify the value on the fly as well.
  • 4:58 - 5:06
    So you can see how making changes fast would be a lot faster than modifying the source code and compiling it and then opening it.
  • 5:06 - 5:13
    So I'm just going to hit cancel, and I'm going to go here into this menu.
  • 5:13 - 5:16
    And you can see a bunch of different things you can do.
  • 5:16 - 5:21
    Box model, that'll show you just the positioning, dimensions, margin, border, etc.
  • 5:21 - 5:27
    You can go to XBL bindings, we'll get into XBL in a future video,
  • 5:27 - 5:32
    But basically you can see attached attributes and functions.
  • 5:32 - 5:36
    An important one that you'll probably use is the CSS rules.
  • 5:36 - 5:42
    So you'll see for this element you'll see all the stylesheets and all the rules that apply.
  • 5:42 - 5:48
    And it shows the file of where the rule is.
  • 5:48 - 5:53
    So if you're just finding out, you want to add style to the URL bar, and you want to know where you should add it.
  • 5:53 - 5:59
    A good place to start is the DOM Inspector, to inspect it, and then you can for example click on each one of these and see what each one is doing.
  • 5:59 - 6:04
    You can also right click on this bottom pane right here.
  • 6:04 - 6:06
    And you can go to insert.
  • 6:06 - 6:10
    And you can add a property, for example background-color.
  • 6:10 - 6:13
    And you can set the value to red.
  • 6:13 - 6:18
    And you can see that up here, it applied the URL bar red change.
  • 6:18 - 6:26
    All of these CSS rules, might be confusing, so you can click here again and you can go to computed style.
  • 6:26 - 6:29
    And that'll show you the overall, what's taking effect.
  • 6:29 - 6:33
    And you can scroll through it.
  • 6:33 - 6:37
    So a couple more things in that menu.
  • 6:37 - 6:42
    You can have used font faces, and JavaScript Objects.
  • 6:42 - 6:48
    So if you want to see the JavaScript object for that DOM element itself, you can click there, and you can see all the properties of that.
  • 6:48 - 6:50
    And you can also expand them on the fly too.
  • 6:50 - 6:57
    So if you're for example coding something, and you're using that element.
  • 6:57 - 6:59
    And you're not sure what the functions are.
  • 6:59 - 7:03
    You can just use the DOM Inspector, and you can see which function you should call there.
  • 7:03 - 7:08
    So that just covered some of the really basic functionality of the DOM Inspector.
  • 7:08 - 7:12
    As you can see it's an extremely useful tool for productivity.
  • 7:12 - 7:17
    Trying to do something without the DOM Inspector is usually really, really hard.
  • 7:17 - 7:20
    And you can actually see what's going on under the hood with the DOM Inspector.
  • 7:20 - 7:23
    So I highly recommend to learn it, and use it.
  • 7:23 - 7:25
    And that's all for this video.
Title:
Introduction to the DOM Inspector
Description:

Firefox development tutorial for using the DOM Inspector to inspect chrome documents.
http://codefirefox.com

more » « less
Video Language:
English
Duration:
07:28

English subtitles

Revisions