Repository navigation
list
sergio edited this page Dec 20, 2020
·
10 revisions
document.getElementById('specific_button')
document.getElementsByClassName('banner_type_div')
document.getElementsByTagName('div')
const card = document.createElement("div");
card.className = 'card'
container.appendChild(card)
bttn.setAttribute('id', toy.id)create element from HTML string
var d = document.createElement('div');
d.innerHTML = some_html;
return d.firstChild;because the one above was returning text rather than an HTML element, I then used the following from here. It creates a complete new document (<html><head></head><body></body></html>) and then creates an element in it, and grabs it with firstChild.
var parser = new DOMParser();
var domString = '<div class="container"><span class="intro">Hello</span> <span id="name"> World!</span></div>';
var html = parser.parseFromString(domString, 'text/html');
document.body.append(html.body.firstChild);document.addEventListener("DOMContentLoaded", () => { ...
toyForm.addEventListener('submit', event => {
event.preventDefault();
postToy(event.target);
}
every //Did all elements satisfy the callback?
.map(callback(element)) //Transform every element and create a new array
.reduce(callback(aggregator, element), starting) //Reduce every element into a new value
.filter
some //Did any element satisfy the callback?
cards.indexOf('jack of clubs', 2 ) // starting index for search //Find the first element that satisfies the callback's index
[4, 6, 8, 10].find(isOdd) // isOdd is a selfmade `function isOdd(element, index, array) {return (element %2 === 1);}`
fetch('http://localhost:3000/toys').then(resp => resp.json()) //GET
fetch('http://localhost:3000/toys', configObj).then(resp => resp.json()) //POST, DELETE, etc.
let configObj = {
method: 'POST',
headers: { "Content-Type": "application/json", Accept: "application/json"}
body: JSON.stringify({"name": "Jessie", "likes": 0})
})
json.forEach(element => { console.log('//do something//') })
img.src = toy.image
Object.assign({}, old_object, {key_to_modify: 'mod', new_key: 'new'}) //=> duplicate obj, no instance