DOM (Document Object Model)

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the top-level object in the DOM hierarchy?

  • document
  • body
  • html
  • window (correct)

What does the HTML DOM allow JavaScript to do?

  • Access and change HTML elements (correct)
  • Only access HTML elements
  • Only change HTML elements
  • Bypass HTML elements

What property of the window.screen object gives the total screen width?

  • availWidth
  • height
  • availHeight
  • width (correct)

Which property specifies the bit value indicating color range?

<p>window.screen.colorDepth (B)</p> Signup and view all the answers

Which of the following methods displays a simple alert box with a message and an "OK" button?

<p>window.alert() (A)</p> Signup and view all the answers

Which method displays a confirmation box with 'OK' and 'Cancel' buttons?

<p>window.confirm() (A)</p> Signup and view all the answers

Which method displays a prompt box with a text input field?

<p>window.prompt() (B)</p> Signup and view all the answers

Which object is a child of the window object?

<p>document (B)</p> Signup and view all the answers

How do you access the page title using the document object?

<p>document.title (D)</p> Signup and view all the answers

What does document.URL provide?

<p>The full URL of the current document (D)</p> Signup and view all the answers

Which property returns the domain name of the document?

<p>document.domain (A)</p> Signup and view all the answers

How can you return the number of images in a document?

<p>document.images.length (D)</p> Signup and view all the answers

What is returned when accessing elements by tag name?

<p>An HTMLCollection (D)</p> Signup and view all the answers

Which method retrieves a single element by its ID?

<p>getElementById() (B)</p> Signup and view all the answers

Which method returns all elements with a specific class name?

<p>getElementsByClassName() (C)</p> Signup and view all the answers

What does the innerHTML property allow you to do?

<p>Insert or change HTML content (A)</p> Signup and view all the answers

What happens when document.write() is executed after the page has loaded?

<p>It replaces all existing HTML content (C)</p> Signup and view all the answers

Which method creates a new HTML element dynamically?

<p>createElement() (D)</p> Signup and view all the answers

Which of the following methods would you use to add a newly created element to the page?

<p>appendChild() (B)</p> Signup and view all the answers

Which method is used to dynamically add or modify attributes of an HTML?

<p>setAttribute() (B)</p> Signup and view all the answers

What is an 'event-handler'?

<p>A function executed in response to an event (D)</p> Signup and view all the answers

Which event fires when the page has completely loaded into the browser?

<p>load (B)</p> Signup and view all the answers

What is a mouseover event?

<p>Fired when the pointer enters an element (D)</p> Signup and view all the answers

What does the event object contain?

<p>Information about the event that occurred (A)</p> Signup and view all the answers

What Javascript functionality allows the selection of multiple options?

<p>Checkboxes (B)</p> Signup and view all the answers

What JavaScript functionality allows the selection of only one options?

<p>Radio button (C)</p> Signup and view all the answers

The .checked property is what type?

<p>Boolean (B)</p> Signup and view all the answers

What does the selectedIndex property of a select element contain?

<p>The index of the selected option (D)</p> Signup and view all the answers

Which tag is used to create the dropdown list?

<p>select (B)</p> Signup and view all the answers

What is a DOM?

<p>Document Object Model (C)</p> Signup and view all the answers

With the HTML DOM, Javascript can access and change

<p>All of the above (D)</p> Signup and view all the answers

Javascript can react to existing HTML events except:

<p>remove other HTML events in the page (C)</p> Signup and view all the answers

Fill in the blank: The top-level DOM object has a _____ child object.

<p>Screen (B)</p> Signup and view all the answers

To access the first image in the document body, specified by an HTML tag, is represented by which of the following?

<p>document.images[0] (C)</p> Signup and view all the answers

Elements can be accessed via Index in Component arrays using the methods bellow, excpet:

<p>Complex (B)</p> Signup and view all the answers

To change text (No HTML), the method used to change the text in the DOM is

<p>innerText (B)</p> Signup and view all the answers

In Javascript, the recommended way to executre a function, specific to an element?

<p>addEventListener (A)</p> Signup and view all the answers

What is the hierarchical tree structure that the browser uses to organize web page components called?

<p>Document Object Model (DOM) (D)</p> Signup and view all the answers

Which property provides the available width of the screen, excluding system UI elements?

<p><code>window.screen.availWidth</code> (C)</p> Signup and view all the answers

What does the 8-bit color depth specify?

<p>256 colors (D)</p> Signup and view all the answers

What does the document.domain property retrieve?

<p>The domain name of the document (A)</p> Signup and view all the answers

What is the primary purpose of document.createElement()?

<p>To create a new HTML element dynamically (D)</p> Signup and view all the answers

Flashcards

Document Object Model (DOM)

A hierarchical tree organizing web page components. Each component relies under the top-level window object.

Screen object

A child object of the DOM presenting the user's monitor resolution in pixels.

Window.screen.width

Total screen width in pixels.

Window.screen.height

Total screen height in pixels.

Signup and view all the flashcards

Window.screen.availWidth

Available screen width, excluding UI like taskbars.

Signup and view all the flashcards

Window.screen.availHeight

The available screen height, excluding system UI elements.

Signup and view all the flashcards

Window.screen.colorDepth

Bit value indicating the color range.

Signup and view all the flashcards

window.alert(message)

Displays a simple alert box with a message and an "OK" button.

Signup and view all the flashcards

window.confirm(message)

Displays a confirmation box with "OK" and "Cancel" buttons.

Signup and view all the flashcards

window.prompt(message, defaultValue)

Displays a prompt box with a text input field.

Signup and view all the flashcards

Document Object

A child of the window object, providing access to the HTML document.

Signup and view all the flashcards

document.title

Retrieves or sets the document's title.

Signup and view all the flashcards

document.URL

Provides the full URL of the current document.

Signup and view all the flashcards

document.domain

Retrieves the domain name of the document.

Signup and view all the flashcards

document.forms.length

The number of forms in the document.

Signup and view all the flashcards

document.images.length

The number of images in the document.

Signup and view all the flashcards

document.links.length

The number of links in the document.

Signup and view all the flashcards

document.scripts.length

The number of scripts in the document.

Signup and view all the flashcards

document.images[0]

Accesses the first image element in the document.

Signup and view all the flashcards

document.getElementById()

Retrieves a single element by its id.

Signup and view all the flashcards

document.getElementsByTagName()

Retrieves all elements with the given tag name.

Signup and view all the flashcards

document.getElementsByClassName()

Retrieves all elements with a specific class name.

Signup and view all the flashcards

innerHTML

Allows setting or retrieving an element's HTML content, supports both text and HTML elements.

Signup and view all the flashcards

innerText

Returns only the content between the opening and closing tags of an element, ignores HTML tags.

Signup and view all the flashcards

document.write()

Writes content directly into the HTML document body, replacing all existing content. Not recommened for modern web dev.

Signup and view all the flashcards

createElement()

Method to create an HTML element dynamically by using createElement(tagName).

Signup and view all the flashcards

appendChild()

Appends a new element inside an existing parent element, placing it at the end of the parent's content.

Signup and view all the flashcards

setAttribute()

Dynamically adds or modifies attributes of an HTML element.

Signup and view all the flashcards

Event Handlers

Functions executed when a particular event happens.

Signup and view all the flashcards

load event

Fired when the page has loaded into the browser.

Signup and view all the flashcards

Handling events

Two main ways to handle events: HTML Event Attributes (Inline) and JavaScript (addEventListener).

Signup and view all the flashcards

Mouse Events

Triggered when the user interacts with the mouse over an element.

Signup and view all the flashcards

Click event

Triggers when the user clicks an element (press + release).

Signup and view all the flashcards

Dblclick Event

A Javascript event that is Fired when the user double-clicks.

Signup and view all the flashcards

Mouseover Event

Fired when the pointer enters an element.

Signup and view all the flashcards

Mouseout Event

Fired when the pointer leaves an element.

Signup and view all the flashcards

Event Object

Contains information about the event that occurred, such as type, location, pressed key, and triggering element.

Signup and view all the flashcards

Checkboxes

Allow users to select multiple options independently.

Signup and view all the flashcards

Radio Buttons

Selecting only one option from a group; all buttons share the same name attribute.

Signup and view all the flashcards

Grouping by name

Checkboxes and radio buttons are grouped by using the same name attribute.

Signup and view all the flashcards

.checked Property

Boolean property indicating whether a checkbox or radio button is selected (true) or not (false).

Signup and view all the flashcards

selectedIndex

Returns or sets the index of the selected option in a dropdown list (starts at 0).

Signup and view all the flashcards

value

Returns or sets the value of the selected option in a dropdown list.

Signup and view all the flashcards

options

Returns a collection of all

To share, set lesson to Public.

Use Quizgecko on...
Browser
Browser