wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Sec-E HTML DOM

Total questions: 54

Worksheet time: 27mins

Name
Class
Date
1.

_________________ allows a string of text to be written to the document

a)

write()

b)

string()

2.

The title of the document, as displayed at the top of the browser window

a)

title

b)

head

3.

For this HTML, how do I select the heading element?

a)

A

b)

B

c)

C

4.

What do you type to create a variable?

(a)  

5.

Is document.getElementById() a DOM property or method?

a)

DOM property

b)

DOM method

6.

Is document.className a DOM property or method?

a)

DOM property

b)

DOM method

7.

How do you change the text to "Alma Thomas"?

a)

A

b)

B

c)

C

8.

document.getElementById(id) has one argument: the ID.

How many arguments does this function have:

updateLocation(painting, museum)



(a)  

9.

Which argument should we use to get the right DOM element?

(a)  

10.

What method can select both artists?

(a)  

11.

const body = document.body;

In JavaScript, what does it do?

a)

Creates a constant which reference to the body element

b)

Creates a duplication of the body element, and every change does not affect the body element

12.

const body = document.body;

What is the type of body?

(a)  

13.

How to get all elements by their tag name in JavaScript?

a)

document.getElementsByTagName();

b)

document.getElementsByTag();

c)

document.getElementsByTabName();

d)

document.getElementByTagName();

14.

How to get all elements by their class name in JavaScript?

a)

document.getElementsByClassName();

b)

document.getElementsByClass();

c)

document.getElementsByClassNames();

d)

document.getElementByClassName();

15.

document.querySelector('#bats');

What does it do in JavaScript?

a)

It uses CSS notation to find the first element with id 'bats'

b)

It uses CSS notation to find the element with class 'bats'

c)

It returns a node list of all the elements with id 'bats'

d)

It find the elements that matches a CSS selector '#bats'

16.

Are document.querySelectorAll('.bats') as same as document.getElementsByClassName('bats')?

a)

Yes

b)

No

17.

In Document Object Model (DOM), all the properties, methods and events that are available to a web developer for manipulating and creating web pages are organised into:

a)

Classes

b)

Objects

c)

Modules

d)

Variables

18.

DOM represents a webpage in what way?

a)

Dynamic structure

b)

Recursive structure

c)

Tree-like structure

d)

Hash table structure

19.

Which of the following is an appropriate event handler for input text?

a)

onclick

b)

onchange

c)

onkeyup

d)

onblur

20.

Which of the following is an appropriate event handler when the user clicks on an element?

a)

onclick

b)

onchange

c)

onkeyup

d)

onblur

21.

Identify the correct code in order to fetch the value entered in username text field?

b)

document.getElementById ("name").value

c)

document.getElementByName ("name").value

d)

None of the these

22.

How to add event handler that would be invoked when the document's body is clicked?

a)

document.onclick = function (){

// do something

};

b)

document.body.addEventListener('click', doSomethingFunction);

c)

document.click = function (){

// do something

};

d)

document.body.addEventListener('onclick', doSomethingFunction);

e)

document.body.onclick = function (){

// do something

};

23.

document.body.addEventListener('click', () => alert('You clicked!'));

Which type of the handler function is in above JavaScript code?

a)

Arrow function

b)

Lambda function

c)

Parentheses function

d)

Short function

24.

What is the difference between keydown and keypress event in JavaScript?

a)

keydown event occurs when a key is pressed

b)

keypress event occurs after keydown event and only occurs for keys that produce character input

c)

keydown event occurs when a key released

d)

keypress event occurs when a key was pushed down

e)

keydown and keyup events occur when a any key is pressed

25.

Can you remove an event in JavaScript?

a)

Yes

b)

No

26.

Which of the method following are used to navigate around the DOM tree?

a)

parentNode()

b)

nextSibling()

c)

nextDaughter()

d)

childrenNodes()

e)

previousChild()

27.

Which of the following is the container for input elements?

a)

Form

b)

Page

c)

Canvas

d)

Input

28.

How many primitive data types in JavaScript?

a)

6

b)

7

c)

5

d)

4

29.

What is callback function?

A callback is a function that is provided as an (a)   to another function.

30.

What does JSON stand for?

a)

JavaScript Object Notation

b)

Java Object Notation

c)

JavaScript Object Normalization

d)

JavaScript Object-Oriented Notation

31.

The output of the below code is:


<p id="demo"></p>


<script>

var text = "";

var i;

for (i = 0; i < 5; i++) {

text += "The number is " + i + "<br>";

}

document.getElementById("demo").innerHTML = text;

</script>

a)

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

b)

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

c)

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

d)

Why is that person using "var"???

32.

The output of the below code is:


<p id="demo"></p>


<script>

var text = "";

var i;

for (i = 0; i < 5; i++) {

text += "The number is " + i + "<br>";

}

document.getElementById("demo").innerHTML = text;

</script>

a)

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

b)

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

c)

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

d)

Why is that person using "var"???

33.

What is the difference between == and ===?

a)

The === operator compares two values, without taking into account their types. == compares the values, but also makes their types into account.

b)

Do I really need to reply this?

c)

The == operator compares two values, without taking into account their types. === compares the values, but also makes their types into account.

d)

The == operator is used to assign a value to a variable. === is used to compare the values of two variables.

34.

What is the DOM?

a)

Is an open standard file format, and data interchange format, that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and array data types

b)

Is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript

c)

Is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable

d)

The Document Object Model is a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document

35.

What are the Javascript data types?

a)

There are seven data types: Boolean, Null, Undefined, Number, String, Symbol, Object.

b)

There are eighth data types: Boolean, Null, Undefined, Number, String, Symbol, Object, Date.

c)

There are nine data types: Boolean, Null, Undefined, Number, String, Symbol, Object, Date, JSON.

d)

Sorry, what do you mean by data type?

36.

What are the pop-up boxes types available in JavaScript?

a)

Alert, Redirect and Prompt

b)

Alert, Confirm and Prompt

c)

Nice try, a pop-up can be done only using jquery or a similar library

d)

Alert, Confirm, Redirect and Prompt

37.

Which image best describes the meaning of null and undefined?

a)
b)
c)
d)
38.

What are HTML Tags?

a)

HTML tags are composed of three things: an opening tag, content and ending tag. Some tags are unclosed tags.

b)

HTML tags are composed of three things: an opening tag, content and ending tag. All tags need to be closed.

c)

HTML tags define metadata about an HTML document. Metadata is data (information) about data.

d)

I didn't know that I was supposed to be studying

39.

What is the use of the required attribute in HTML5?

Name: <input type="text" name="name" required>

a)

This adds a red border over the input box for the user to visually recognize that it is required.

b)

It forces a user to fill text on the text field or text area before submitting the form. It is used for form validation. But, the "required" attribute is not properly written in this example.

c)

It would be nice to have that functionality, but due to browser compatibility it does not work and manual validation is required.

d)

It forces a user to fill text on the text field or text area before submitting the form. It is used for form validation.

40.

What are the new <input> types for form validation in HTML5?

a)

The new input types for form validation are text, textarea, radio, email, URL, number, tel, and date.

b)

The new input types for form validation are text, area, radio, email, URL, number, tel, and date.

c)

The new input types for form validation are email, URL, number, tel, and date.

d)

All these options are available since previous versions of HTML.

41.

How to write HTML code dynamically using JavaScript?

a)

document.getElementById('some-div-id').innerHTML="<h2>This is heading using JavaScript</h2>";

b)

document.getElementById('some-div-id').innerHTML.val("<h2>This is heading using JavaScript</h2>";)

c)

document.getElementById('some-div-id').innerHTML.html("<h2>This is heading using JavaScript</h2>";)

d)

document.getElementByTagName('some-div-id').innerHTML="<h2>This is heading using JavaScript</h2>";

42.

What is the output of 10+20+"30" in JavaScript?

a)

102030 because since there is a string, all the + will be treated as string concatenation operator (not binary +).

b)

102030 because before you perform arithmetic operations you would have to explicitly convert those values to an actual number.

c)

That will throw an unhandled exception, a try catch block is required to prevent it.

d)

3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).

43.

How to submit a form using JavaScript by clicking a link?

a)

<form name="myform">

<a href="javascript: document.myform.submit();">Submit</a>

</form>

b)

<form name="myform">

<button type="button" onclick="javascript: document.myform.submit();">Click Me!</button>

</form>

c)

<form name="myform">

<input type="submit" value="Submit">

</form>

d)

<form name="myform">

<span id="link" onclick="javascript: document.myform.submit();"></span>

</form>

44.

Select the correct option:

a)

The getElementsByName() method returns a live HTMLCollection of elements with the given tag name.

The getElementsByTagName() method returns a collection of all elements in the document with the specified name (the value of the name attribute), as an HTMLCollection object.

b)

The innerHTML property sets or returns the text content of the specified node, and all its descendants.

The innerText property sets or returns the HTML content of an element.

c)

let allows you to declare variables that are limited to the scope of a block statement, or expression on which it is used, unlike the var keyword, which declares a variable globally, or locally to an entire function regardless of block scope

d)

The difference between POST and PUT is that POST requests are idempotent. That is, calling the same POST request multiple times will always produce the same result. In contrast, calling a PUT request repeatedly have side effects of creating the same resource multiple times.

45.

•The __________ property can be used to write the dynamic text on the html document. Here, text will not be interpreted as html text but a normal text.

a)

innerHTML

b)

innerDocument

c)

innerText

d)

innerTag

46.

It is used mostly in the web pages to generate the dynamic content such as writing the validation message, password strength etc

a)

innerHTML

b)

innerDocument

c)

innerText

d)

innerTag

47.

•The __________________property can be used to write the dynamic html on the html document.

a)

innerHTML

b)

innerDocument

c)

innerText

d)

innerTag

48.

•It is used mostly in the web pages to generate the dynamic html such as registration form, comment form, links etc.

a)

innerHTML

b)

innerDocument

c)

innerText

d)

innerTag

49.

writes the given string on the doucment.

a)

write("puihaha")

b)

document.innerHTML

c)

document.innerText

d)

document.innerTag

50.

•The document object represents the whole html document.

a)

True

b)

False

51.

•The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."

a)

True

b)

False

52.

JavaScript DOM , could be manipulated using these except for:

a)

Finding HTML elements by tag name

b)

Finding HTML elements by value

c)

Finding HTML elements by class name

d)

Finding HTML elements by id

53.

JavaScript can't change all the HTML elements in the page

a)

True

b)

False

54.

JavaScript can change all the HTML attributes in the page

a)

Fact

b)

Baseless