JS Flashcards
save to local storage
localStorage.setItem(“key”, value)
convert from js object to JSON string
JSON.stringify(myObject)
get from local storage
localStorage.getItem(itemKey)
Flex
Container
display:flex
flex-direction: row/column row-reverse
justify-content: space-between
align-items: center, flex-start, flex-end, stretch
Items
flex-shrink
flex-grow
flex-basis
CSS descendant selectors
space, for example: ul.my-things li , List items that are descendants of the “my-things” list
General Sibling combinator selector
Tilde ~ selects all elements that are next siblings of a specified element
li.red ~ li , selects all the li’s that come after an li with a class of red
Select all elements that match various combinators (and)
just type them together without spaces
apply same css to different selectors (or)
separate them using commas
direct child selector
< , just the direct children
Css Adjacent Sibling Combinator
Selects only one sibling that comes after a selector
li.red + li, selects only the one li that comes after the li with the class of red
css pseudoclasses
hover, li:hover
:focus (buttons & form inputs when clicked)
:checked
:disabled
li:first-child
pseudo class to select the first child, last child, or n child, only child, first of type, last of type
li.red:first-child (only selects the first li if it has the class of red)
li:last-child
li:nth-child()
li:only-child (selects the li only if its the only child inside a block)
li:first-of-type (the first item of type li inside a block)
li:nth-of-type()
li:last-of-type
pseudo selector not
li:not(.green), pseudo selector that doesn’t have the class of green
pseudo elements
div.red::before, div.red::after Adds styling before or after de div with a class of red
Styling data attribute selectors. simple and with a particular value
[data-red]{ }
[data-red=”true”]{ }
attribute selector that matches the beginning
[data-red^=”12”]
attribute selector that matches the end
[data-red]$=”69”
<div></div>
Red data attribute selector that has 34 somewhere
<div></div>
[data-red]*=”34”
Adds a text to an element
element.innerText =”my new text” (visible content in a node)
or element.textContent= “My new text” (all content)
clone a template
const template = document.querySelector(“#myTemplate”)
const templateClone = template.content.cloneNode(true)
add a newElement to a listElement
listElement.appendChild(newElement)
check edge case inside a function where the input text is empty
if(inputText === ‘ ‘) return
add to an array
myArray.push(myText)
save to local storage, and what if saving an array value
localStorage.setItem(“keyName”, stringValue)
if the stringValue is an array
localStorage.setItem(“keyName”, JSON.stringify(stringValue))
load from local storage
function loadItems(){
const storedItems = localStorage.getItems(KEY_NAME)
return JSON.parse(storedItems) || [] // converts to js object or array
}
event listener when we interact with a list
list.addEventListener(“change”,e=>{
e.target.matches(“[data-checkbox-name]”)
})