Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.