Quiz
- Can you talk more about "data- attributes"? Are these attributes we're creating or are they pre-existing and we're just giving them values?
Good question. These are attributes we are making up. Suppose we had a web page with a bunch of employee entries on it. They could be represented like this:
Why would you do this? Maybe we want that info available via JS (some kind of modal? pop-up?) but not displayed by default. Who knows?
The point is that we are allowed to sprinkle addition information into the HTML by using
data-attributes. - Can you explain the difference between the jQuery object and the event object?
Sure. They are entirely different. There are event objects even if you don't use jQuery at all, maybe you don't even load it:
The event object is created by the browser and is passed to our event handler when the browser calls our event handler.
Our event handler can use it or ignore it.
One important method is preventDefault
- When is it appropriate to get values from another file?
Great question! We'll talk a lot more about modules in a week, but this question gets to that topic.
Ideally, programs are built in a modular way: separate components that individually make sense and together comprise a working whole. Typically, a module is defined in a file or set of files.
Consider the
mathmodule. In Python and JS, a lot of useful mathematical functions and values are organized there.Would it be appropriate to access a value like
math.PI? Of course!What if there were some internal value, like
math.sqrt_algorithm? Should we use it in our code? rely on it? Almost certainly not. If it changed in some unpredictable way, our code would almost certainly break.It's important to stick to published,
documentedinterfaces.I can tell you an amusing story about setting
falsetotrue. - No question for now!
great!