js Flashcards
how to check a click is touch or mouse click
onclick => (e) => e.type === “touchdown”
how to get the x position in touch
(e) => e.touches[0].clientX
how to get the node of clicked element
(e) => element = e.target
how to style an element
element.style.nameOfStyle = “string”
what it selects ? document.getElementsByClassName(“item”)
return an array
how to get the class name of a fired event from event Listener
e.target.className
target vs currentTarget
Basically, events bubble by default so the difference between the two is:
target is the element that triggered the event (e.g., the user clicked on)
currentTarget is the element that the event listener is attached to.
how to transfer the id via in an event
in sender
event.dataTransfer.setData( ‘text/plain’, event.target.id)
in the receiver
event.dataTransfer.getData(“text”)
200 < x < 500 ?
return x >= min && x <= max
how to map array of the nodelist
Array.from(nodelist).map
we have a random number of items in a container, we need to define an event listener on them, how we can get the active item
if ( e.target !== e.currentTarget ) // make sure that the item is not container itself
actvieItem = e.target
append vs appendChild
.append accepts Node objects and DOMStrings while .appendChild accepts only Node objects
.append does not have a return value while .appendChild returns the appended Node object
.append allows you to add multiple items while appendChild allows only a single item
Object.assign(target, …sources)
Object.assign() is used for cloning an object.
Object.assign() is used to merge object with same properties.