Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Ben Os
Ben Os
20,008 Points

Stuck in task 2 in this exercise of "DOM scripting by example"

This is the tongue of the question of task 2:

"Alter the callback function to use the event object. Using the event object, ensure that the browser's default form submit behavior does not occur when the form is submitted".

https://teamtreehouse.com/library/dom-scripting-by-example/adding-and-removing-names/using-the-submit-event


I think I missed from the video what is the "Event object". I know what is and event and what is an object, but I might missed the particular meaning of "event object". I did try to use preventDefault() inside the event handler row, but without success.

1 Answer

Amin Ruhul
PLUS
Amin Ruhul
Courses Plus Student 4,762 Points

"Event object" means Event has so many properties. For example, click event, keydown event,

event also has DOM element. For more read: https://www.w3schools.com/jsref/dom_obj_event.asp

What meant on that questions:

const form = document.querySelector('form');
const submitButton = form.querySelector('[type=Submit]');

form.addEventListener('submit', (e) => {
  e.preventDefault();
});
Ben Os
Ben Os
20,008 Points

I actually putted e inside the parenthesis but surly I was wrong. Thank you for explaining this Amin.