old cards Flashcards
(108 cards)
list the “getEl” methods used to traverse the DOM & and what they return.
________________________________________________________________________________________________
then describe what this code could/should be doing on a page & what the last line’s value would be :
(1)
document.getElementsByClassName(‘special’);
// value —-> HTMLCollection(3) [p.special, li.special, li.special]
(2)
const ul = document.getElementsByTagName(‘ul’)[0]
(3)
ul.getElementsByClassName(‘special’);
// —> what would this value be?
(4)
ul.getElementsByTagName(‘li’);
// —> what would this value be?
getElementById(‘idNameAsAString’) — returns the element as an object that has that id, if there’s no element with that id it returns null
getElementsByTagName(‘elementTagNameAsAString’) — returns the elements in an array-like object that you can iterate over (key = index, value = one of the elements; the element itself is an object with its own properties and methods); returns an empty object if there are no elements on the document that match the tag passed in
*note the ‘s’ in the method name - tells you you’ll get a collection back
getElementsByClassName(‘classNameAsString’) — returns the elements in an array-like object that you can iterate over (key = index, value = one of the elements in the class; the element itself is an object with its own properties and methods);
*note the ‘s’ in the method name - tells you you’ll get a collection back
______________________________________________________________________________________________________________________________________________________
(1) selects all elements in the class special, happens to be a paragraph and two list elements
(2) store the first ul on the page in a constant
(3) selects all elements within the first ul on the page that’s has the class ‘special’
// HTMLCollection(2) [li.special, li.special]
(4) selects all li elements within the first ul
// HTMLCollection(3) [li.special, li, li.special]
describe the “swiss army knife” of document selectors and it’s two forms
bonus question : what is this —> #
querySelector
can do everything the ‘get Element(s) By’ methods do and can select anything. pass in a CSS selector as a string.
examples :
—-> by element type, like ‘h2’
—-> by id, like ‘#red’
—-> by class, like ‘section ul li.big’, which selects the first li with a class of big nested in a ul, which itself is nested in a section)
—-> by attribute, like ‘input[type=”password”], which selects the first input with the type password
it selects only the first match and returns the element in an object
______________________________________________________________________________________________________________________________________________________
querySelectorAll
same as querySelector, except it returns all matches in an array-like object
______________________________________________________________________________________________________________________________________________________
—> octothorpe
list & describe the properties needed to do the following :
access/reassign text inside an element
access/reassign HTML code inside an element
access the element one step up on the DOM tree
access element(s) one step down on the DOM tree
innerText property —- returns all of the text inside that element, no matter how many elements/nested elements are within the element selected; can reassign an element’s innerText value (formatted as a string). textContent is similar, slightly less useful
innerHTML —- return a string that contains everything that was written in the HTML doc in the element the property is being called on (if there’s only input tags with no actual text, for example, innerHTML would show the entire tag, attributes, etc — innerText wouldn’t show anything). innerHTML also reads tags and displays correctly.
example of the difference between the two :
if your webpage had an h1 — “My Webpage”
const heading = document.querySelector(‘h1’);
heading.innerText += ‘<b>!!!!!</b>’
// the h1 would read —> My Webpage<b>!!!!!</b>
heading.innerHTML += ‘<b>!!!!!</b>’
// the h1 would read —> My Webpage!!!!!
_________________________________________________
selectedElement.parentElement —-> returns the parent element
selectedElement.children —-> returns the children of the selected element in an array-like object
list the methods used to manage attributes on HTML elements
getAttribute —
takes one argument; pass in the attribute you’re looking for on the element you calling the getAttribute property on (in a string) & it’ll return that value
setAttribute — takes two arguments, the attribute you want to set & the value you want to assign it). can also be used to conpletely change an attribute as well (you could have a checkbox input, and reassign the type to radio, for example, once you select it)
const range = document.querySelector(‘input[type=”range”]
range.getAttribute(‘max’)
// “500” —> gives the max value assigned to the max attribute for this range slider input element in your HTML
range.setAttribute(‘max’)
// “500” —> gives the max value assigned to the max attribute for this range slider input element in your HTML
describe the relationship between HTML / CSS / JS
HTML is the “what”, or the nouns, the contents, the underlying structure / bones of a webpage – headers, buttons, etc
CSS is the description/style of the structure, makes it look good (adjectives)
JS is the how – its the action that makes everything function – its the logic that determines how everything behaves
explain / describe the usefulness of the following tags :
paragraph (shortcut to fill with meaningless text?)
h1-h6
ol (how to add list items?)
ul (how to add list items?)
hr, br
paragraph element – grouping of related content (can use lorem*4 to fill in lorem ipsum text)
heading elements – don’t use for size (css can change the default sizes) – use for organizational / structural purposes (hierachy) to indicate main topics, pages should only have one H1, subtopics etc; should never have an h4 without an h3, etc — this is important for search engines to understand what is important
ordered lists (numbered) with <li></li> elements (can have nested lists, adding ol/ul within li as sub lists)
unordered lists (bulleted) with <li></li> elements
horizontal rule (line across the page), line break (start a new line)
what is the name of the standardized markup structure for any html document?
what is the purpose of each section :
head
body
lastly, what is an html entity?
html boilerplate
- head element contains title (tab browser & search results name) and metadata - info ABOUT the page, like title, css or scripts
- the body, which contains the visible content of the page
an html entity starts with an ampersand and ends with a semi-colon — they are used to display special characters.
The most important entities are: (non-breaking space — to make sure two words always appear on same line together), < (less than sign), > (greater than sign) and © (copyright symbol).
describe the usefulness of the following tags & how to manage height and width of both :
div
span
describe / give examples of semantic markup
div - generic, BLOCK LEVEL container to that fills the width of page — set height and width properties to whatever you want in css
span - generic, INLINE container (often used for text) — doesn’t respect normal height and width — need to set display property to inline-block, then set height and width
semantic markup adds MEANING rather than having a bunch of divs/spans.
The semantic elements in HTML5 are: <header> (often includes navigational content), <footer>, <nav>, <main>, <aside>, <article> (any self contained data), <section>, <figure>, <time> and <mark>.</mark></time></figure>
what is a form element and what does it (and the required attribute) do?
form element – empty container section w/ interactive controls for submitting info; action attribute specifies WHERE the form data should be sent when the form is submitted (an http request will be sent to wherever action is set to)
what do each of the following attributes do in an input tag?
- type (list a few different types, what’s different about the radio type, and the input-type shortcut)
- placeholder
- name
- value
- id (how does this relate to label tag… also what is a label tag)
- required
…there are also other types of tags for forms that are helpful to be aware of :
button
text area
select w/ options (how does this relate to label tag)
- type — text, password, checkbox, range, file; for the radio type, all options for selection must have the same name to group them all together; input:type (so, input:text or input:checkbox, etc)
- placeholder — the words in a text box before you start typing
- name — the label under which the data is being sent to the server; how the server recognizes the data; MANDATORY attribute (servers receive queries in a name - value pair)
- value — for text, the value is whatever is being entered into the textbox, otherwise when the input is selected (for radio, checkbox, select/option), you must manually decide what value gets sent to the server when an option is picked
- id — rather than a random text box or radio button floating on the webpage, this id serves as a label for what this input is indicating. you’ll need to create an associated label tag, and the for attribute will be set to the id of the input that the label is associated with
label– associates text element with an input element (checkbox, etc); adding an id attribute in the input element, and setting the for attribute in the label element equal to the same thing links them together (it becomes a label “for” the input). The id needs to be unique for that particular label/input combo and should not be reused - required — doesn’t equal anything, just a browser validation put at the end of an input tag to ensure something is entered or selected before submission
button – text between the tags determines the words on the button; by default, buttons submit the form it’s a part of (if it’s outside a form, it does nothing)
select is like a list, option elements are like li
text area is a large text box with a scroller on the side for paragraph entries
anchor tags :
what is it, and what is it’s main attribute?
how do you create a URL from within your folders?
how do you link to other parts of the same page (also called a fragment)?
how do you jump to the top of a page?
optional :
how do you get a URL to open in a separate tag?
how do you create an email link?
anchor tag - hyperlink to another webpage, email address, file or some other place on the same page;
href attribute passed into tag to tell where to go when link is clicked (is the URL or path the tag points to)
forward slash to access higher folders, then to work down hierarchy to other files
add an id attribute for the section you want to jump to & create a anchor with the href attribute set to #whateverTheIdNameWas
create a anchor with the href attribute set to # (add whatever text between the tags)
optional :
set target attribute to _blank in anchor tag
set href to mailto:yourEmailAddress@gmail.com
practice
in an html doc in vscode:
using ONLY shortcuts — highlight a word, open command pallet and wrap it in a tag
create these two in html using emmet :
nav with a ul nested inside, with 5 li nested in ul - w/ each li having an anchor tag
&
a paragraph, div & li one after another
shift start <
shift alt P
wrap w/ abbrev
type tag
nav>ul>li*5>a (child, multiplication)
p+div+li (sibiling)
https://docs.emmet.io/cheat-sheet/
images & videos :
what happens with the object-fit property is set to cover?
when adding a video element to a page, how do you make sure there are play, volume buttons etc?
optional :
how do you get the video to start playing as soon as it loads?
how do you get the video to repeat automatically?
what is a common best practice for video tags to catch unsupported browsers?
image tag + src, alt attribute
image tag – embeds image into a document
source attribute = path to image you want to embed (either local or hosted somewhere else);
alt attribute = holds a text description of the image (optional but incredibly useful for accessibility)
object-fit makes sure the image covers it’s containing box (resizes and crops to prevent distortion)
video element — add the controls attribute with no value
optional:
autoplay attribute with no value
loop attribute with no value
include a statement like ‘Your browser doesn’t support videos.’ between the tags - this will show up for unsupported browsers
table :
tr, th, td, colspan
…there’s also
thead, tbody, tfoot
table - only used for displaying tabular data —- ALL elements defining the table must be wrapped in table tags to show up formatted as a table
table row (defines a row of cells in a table, just a declaration like table itself — not visible until you add cells)
header cell & data cell – creates actual cells within the row
colspan is an attribute that allows cell to span multiple rows
thead, tbody, tfoot – just declare/define parts of a table
how do you connect an html and css file?
link tag in the head of html boilerplate; href attribute should point to the style sheet
review these useful properties :
border (list the values)
overflow
text-align
font-weight
text-decoration
line-height
font-size
letter-spacing
font-family (first choice, backup font or generic family name)
https://www.cssfontstack.com/
border — width style color (any of these can be left out and it’ll still work)
overflow — if you have a fixed size container and the content spills out, you can set this to auto to allow for scrolling (bar shows up when content overflows, bar is hidden if not)
text-align – left, center, right aligned
font-weight – boldness
text-decoration – decorative lines on text (color, under/over/through, thickness, dotted/dash/wavy etc)
line-height — space around characters (think college vs wide ruled)
font-size
letter-spacing — space between letters
font-family (first choice, backup font or generic family name)
what are pseudoclasses and what is their syntax?
color + keyword (no space) that’s added to an element based on its position in a family (nth-of-type, first-of-type, nth child) OR how the element is being interacted with by the user (‘checked’ for radio buttons or checkboxes, ‘hover’ for images, divs, links, etc, ‘visited’ for hyperlinks, ‘active’ etc)
.post button:hover {
color : orange;
}
/* every button created within an element in the post class will turn orange when the user hovers over it */
MDN : A pseudo-class is a selector that selects elements that are in a specific state, e.g. they are the first element of their type, or they are being hovered over by the mouse pointer. They target some bit of your document that is in a certain state, behaving as if you had added a class into your HTML.
describe syntax & define the following terms :
rule
class
id
idName {
rule : used to style all instances of the selected element
selector {
property : value;
}
h1,h2 {
property : value;
}
(DON’T forget semicolons! needed at the end of property declarations for the effects to take place)
___________________________
class : used to style all elements with this given class
.className {
property: value;
}
___________________________
id :
ids can be added to any element as a hook to whatever style you create for that specific element. only one element should have one id – keep these to a minimum & don’t overdo them
property : value;
}
products p {
practice :
do the following using emmet abbreviations
create three section elements with an id whose value is set to “product”
create an article with an h1 whose class is “returns”
what would this relational selector do? :
color : red; }
section#product
article.returns*3
(1) every paragraph in the section with the id “products” will turn red
what are pseudo-element selectors? describe the syntax and give a few examples
MDN : Pseudo-elements act as if you had added a whole new HTML element into the markup, rather than applying a class to existing elements. Pseudo-elements start with a double colon.
April’s thoughts : pseudo-classes decide how an element is styled based on their state (hovered over, clicked, being the nth occurrence of its type, etc). Pseudo-elements style parts of an actual element that can’t normally be selected on its own (there’s no first letter element)
::first-letter
::first-line (first line of paragraph)
::selection (changes color of what’s highlighted)
::before or ::after (to insert something before/after the content of an element — you set the content selector to whatever you want & the display selector to block)
other styling details :
which color system(s) can you use to change the opacity of a color?
describe the values for the border and border-width properties
rbga or hsla (a is alpha, set between 0 and 1 for opacity)
border : width (10px) style (solid) color (royalblue);
border-width : top (10px) right(20px) bottom(10px) left(20px) OR 10px 20px; — clockwise
positioning :
what is z-index?
relative vs absolute vs fixed positioning
font measurements : px, %, vh/vw, rem
float property
the z-index property moves elements along the z-axis and controls depth (imagine the computer screen is at 0 depth). this can move an element in front of (1 or greater z-index which brings the element towards you) or behind other elements (z-index : -1)
relative : set/move elements around relative to it’s normal/default position
absolute : set/move elements around relative to the container (container position must be relative, moving element must be absolute)
fixed : set/move elements based on the viewport
px : absolute & not responsive
% : certain percentage of parent element
vh/vw : percent of viewport height or width
rem : element size will adjust based on default font size which you can set
float property
talk through these lines :
- function multiplyBy2 ( ) { }
- const result = multiplyBy2 ( );
- return multiplyBy2;
“creating a function, labeled multiplyBy2 and storing the function definition in XXXXX memory” —- global memory if out in the open, otherwise its local
“creating a constant called result in in XXXXX memory, and assigning it the evaluated result of invoking multiplyBy2”
“return the function definition of multiplyBy2”
order the steps in which you’d read through this code, line by line and explain what’s happening in each step :
\_\_ function outer ( ) { \_\_ let counter = 0; \_\_ function incrementCounter ( ) { \_\_ counter ++; } \_\_ return incrementCounter; }
\_\_ const myNewFunction = outer( ); \_\_ myNewFunction( ); \_\_ myNewFunction( );
1 function outer ( ) { ===> create a function labeled outer, and STORE THE FUNCTION DEFINITION in global memory 3 let counter = 0; ===> declare a variable labeled counter & assign counter the value of zero 4 function incrementCounter ( ) { ===> create a function labeled incrementCounter & store the func def in local memory "7" & "9" counter ++; ===> } 5 return incrementCounter; ===> return the func def of increment counter and store in global constant myNewFunction }
2 const myNewFunction = outer( ); ===> declare a constant myNewFunction & assign it the return value of the invocation of the function outer* 6 myNewFunction( ); ===> invoke myNewFunction** (functionality formerly known as incrementCounter aka counter++) "8" myNewFunction( ); ===> invoke myNewFunction** (functionality formerly known as incrementCounter aka counter++)
*this means myNewFunction takes on the definition of incrementCounter (aka THE FUNCTIONALITY OF INCREMENT COUNTER => counter++); so when you invoke myNewFunction, you’re essentially just incrementing counter – also note that the same function definition has multiple labels, one within a local execution context & one in global memory
**even though we look back up the page to incrementCounter, JS is looking at the returned function definition of incrementCounter stored in myNewFunction