Front 01 (Q16)
Which property references the DOM object that dispatched an event?
- self
- object
- target
- source
Solution
- self
- object
- target
- source
Which property references the DOM object that dispatched an event?
Which statement is true about the async
attribute for the HTML script tag?
What's one difference between the async
and
defer
attributes of the HTML script tag?
defer
attribute can work synchronously.
defer
attribute works only with generators.
defer
attribute works only with promises.
defer
attribute will asynchronously load the scripts in order.
<p class="pull">lorem ipsum</p>
Which statement references the DOM node created by the previous code?
document.querySelector('class.pull')
document.querySelector('.pull');
document.querySelector('pull')
document.querySelector('#pull')
document.querySelector('class.pull')
document.querySelector('.pull');
document.querySelector('pull')
document.querySelector('#pull')
Which method cancels event default behavior?
cancel()
stop()
preventDefault()
prevent()
cancel()
.
stop()
.
preventDefault()
.
prevent()
.
Which method do you use to attach one DOM node to another?
attachNode()
getNode()
querySelector()
appendChild()
attachNode()
getNode()
querySelector()
appendChild()
button.addEventListener(
'click',
function (e) {
button.className = 'clicked';
},
false,
);
You've written the event listener shown above for a form button, but each time you click the button, the page reloads. Which statement would stop this from happening?
e.blockReload();
button.preventDefault();
button.blockReload();
e.preventDefault();
e.blockReload();
button.preventDefault();
button.blockReload();
e.preventDefault();
Which statement selects all img
elements in the DOM tree?
Document.querySelector('img')
Document.querySelectorAll('<img>')
Document.querySelectorAll('img')
Document.querySelector('<img>')
document.querySelector('img')
document.querySelectorAll('<img>')
document.querySelectorAll('img')
document.querySelector('<img>')
Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?
Which tag pair is used in HTML to embed JavaScript?
<script></script>
<js></js>
<javascript></javascript>
<code></code>
<script></script>
<js></js>
<javascript></javascript>
<code></code>
If your app receives data from a third-party API, which HTTP response header must the server specify to allow exceptions to the same-origin policy?
//HTML Markup
<div id="A">
<div id="B">
<div id="C">Click Here</div>
</div>
</div>
//JavaScript
document.querySelectorAll('div').forEach((e) => {
e.onclick = (e) => console.log(e.currentTarget.id);
});
What is the output that is printed when the div
containing the text "Click Here" is clicked?
<h1 class="content">Dapelican 1</h1>
<div class="content">
<span class="content">Dapelican 2</span>
</div>
Which statement can be used to select the element from the DOM containing the text "Dapelican 2" from the previous markup?
document.querySelector("div.content")
document.querySelector("span.content")
document.querySelector(".content")
document.querySelector("div.span")
document.querySelector("div.content")
document.querySelector("span.content")
document.querySelector(".content")
document.querySelector("div.span")
How would you add a data item named animal
with a value of sloth
to local storage for the current domain?
LocalStorage.setItem('animal', 'sloth');
document.localStorage.setItem('animal', 'sloth');
localStorage.setItem({ animal: 'sloth' });
localStorage.setItem('animal','sloth');
LocalStorage.setItem('animal', 'sloth');
document.localStorage.setItem('animal', 'sloth');
localStorage.setItem({ animal: 'sloth' });
localStorage.setItem('animal', 'sloth');
Which document method is not used to get a reference to a DOM node?
document.getNode();
document.getElementsByClassName();
document.querySelectorAll();
document.querySelector();
document.getNode();
document.getElementsByClassName();
document.querySelectorAll();
document.querySelector();
<script type="text/javascript">a = 5 + "9"; console.log(a);</script>
What will be the output of the previous code snippet?
14
.
59
14
.
59
Which of the following methods can be used to display data in some form using Javascript?
document.write()
console.log()
window.alert()
document.write()
.
console.log()
.
window.alert()
.
Note that using document.write(
) is
discouraged.
Which statement is applicable to the defer
attribute of the HTML
<script>
tag?
defer
allows the browser to continue processing the page while the script loads in the background.
defer
causes the script to be loaded from the backup content delivery network (CDN).
defer
blocks the browser from processing HTML below the tag until the script is completely loaded.
defer
lazy loads the script, causing it to download only when it is called by another script on the page.
defer
allows the browser to continue processing the page while the script loads in the background.
defer
causes the script to be loaded from the backup content delivery network (CDN).
defer
blocks the browser from processing HTML below the tag until the script is completely loaded.
defer
lazy loads the script, causing it to download only when it is called by another script on the page.
<h2 id="cleverest">girls</h2>
How would you change the color of this header to pink?
document.getElementByName("cleverest").style.color = "pink";
document.getElementsByTagName("h2").style.color = "pink";
document.getElementByName("h2").style.color = "pink";
document.getElementById("cleverest").style.color = "pink";
document.getElementByName("cleverest").style.color = "pink";
document.getElementsByTagName("h2").style.color = "pink";
document.getElementByName("h2").style.color = "pink";
document.getElementById("cleverest").style.color = "pink";
getElementsByTagName()
returns an HTMLCollection.
Note that the answer document.getElementsByTagName("h2")[0].style.color = "pink";
would have been OK.