Quiz
- What's the difference between a property and an attribute?
Good question. The words are very similar in meaning (in an ordinary dictionary) and are used in very similar ways in coding.
Both are ways to talk about parts, facets, or aspects of things (more synonyms).
In this course, a
propertyis a part of an object/dictionary. Like this:An
attributeis a part of an HTML element (tag). Like this: - Could you explain more about how "data-" attributes are used in code? data-role="trigger" and data-image-url="imgs/otter1.jpg" seem to have been used in different ways.
Sure. The
data-attributes are things that we as developers can add information to the HTML for our own purposes.Beyond that, we can't say much, any more than we can say what, say, variables are used for: they hold information.
In Ottergram, we use the following
data-attributes:- the
data-roletells us what role the element plays. We have triggers (the clickable thumbnails) and also a target and a title. The latter two are modified by the JS. - the
data-image-urlis what value to change thetargetto - the
data-image-titleis what value to change thetitleto
- the
- How does the "each" method work? What is "elt"?
elt is a common abbreviation for the word element, which is a member of a set, array or list. Or an HTML element.
See MDN Array.map
.eachis a lot like.forEachwhich is similar to.map. The difference is thatmapandforEachwork on regular JS arrays, but.eachworks on jQuery wrapped sets.mapexecutes the callback (the function argument) for each element and collects return values in a new array.forEachexecutes the callback for each element but doesn't collect return values..eachexecutes the callback for each element and doesn't collect return values.
The callback function for map/forEach is
function (elt, index, array) {}.For
each, the callback function isfunction (index, elt){} - Can we talk more about the preventDefault method? Is it primarily for hyperlinks/are there other ways to make a button that visually looks like a hyperlink but isn't one?
Yeah, it's used for hyperlinks a lot. Can also be used for form submission buttons, but we haven't gotten to those yet.
-
I was actually very confused by the reading starting from "data attributes" and all the way to "attaching the event handlers". I think the reading was rooted in examples that I couldn't always follow. I guess more specifically, could we talk about the implementation process in more detail? For example, what is happening in these sections of code:
function setDetails(imageUrl, titleText) { $(detailImage).attr('src', imageUrl); $(detailTitle).text(titleText); } imageFromThumb(thumbLinks[0]); titleFromThumb(thumbLinks[0]); imageFromThumb(thumbLinks[1]); titleFromThumb(thumbLinks[1]); function setDetailsFromThumb(thumbnail) { setDetails(imageFromThumb(thumbnail), titleFromThumb(thumbnail)); }I'm sorry the reading was confusing. I can try to improve it. Please help me do so.
Let's look at those examples using ottergram
- Could you please go over the ottergram JavaScript again? Thank you so much!
Sure! I'll take as much time as people need.
- I don't really have any. Can't wait to code it myself!
Great! Let's do it!