DOM 2 Flashcards
What event is fired when a user places their cursor in a form control?
focus
What event is fired when a user’s cursor leaves a form control?
blur
What event is fired as a user changes the value of a form control?
input event
What event is fired when a user clicks the “submit” button within a ?
submit event fires when a is submitted.
What does the event.preventDefault() method do?
The Event interface’s preventDefault() method tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
What does submitting a form without event.preventDefault() do?
by default, on submission of a form, the page will redirect and refresh. The biggest reason that this becomes a problem is that if you wanted to do anything with that information later on, you can’t.
What property of a form element object contains all of the form’s controls.
The HTMLFormElement property elements returns an HTMLFormControlsCollection listing all the form controls contained in the element.
What property of form a control object gets and sets its value?
value property
What is one risk of writing a lot of code without checking to see if it works so far?
it will be very difficult to debug later on in code.
What is an advantage of having your console open when writing a JavaScript program?
to catch errors early on
Does the document.createElement() method insert a new element into the page?
No
How do you add an element as a child to another element?
appendChild();
What do you pass as the arguments to the element.setAttribute() method?
name and value.
for example: Element.setAttribute(name, value);
What steps do you need to take in order to insert a new element into the page?
- create the element using createElement();
- give it content using createTextNode();
- add it to the DOM using appendChild();
What is the textContent property of an element object for?
to give the newly created element content.