[S4L4] Components 2 Flashcards

1
Q

Was bieten Data Attribute über den DOM?

A

-Auch ohne Klassen oder IDs auf Nodes des DOMS zuzugreifen und Selections zu machen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Wie sieht ein Data Attribute aus?

A

<div>Lambda School</div>

div[data-school='Lambda']{
    /* CSS Style rules here */
  }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Wie greift man auf .dataset Properties des DOMs zu?

A

<div>Lambda School</div>

 div[data-school='Lambda']{
    /* CSS Style rules here */
  }
const school = document.querySelector('.school');
  const schoolName = school.dataset.school;
  console.log(schoolName); //Lambda
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Wie benutzt man data attributes über querySelectors?

A

const schoolElement = document.querySelector(“div[data-school=’Lambda’]”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Mit welchen Schritten geht man vor um

A
// Step 3: Define our class that will create a new object!
class Link {
  constructor(link) {
    this. link = link;
    // 1,2,3,4
    // console.log(this. link.dataset.tab); 
    this.content = document. querySelector(`.content[data-tab='${this.link.dataset.tab}']`);
    // console.log(this.content); 
    // This is creating a new Content object using the DOM content object
    //console.log(this. content);
    this.content = new Content(this. content);
    //console.log(this. content);
    // this.link. addEventListener('click', this.linkClick. bind(this));
    this.link. addEventListener('click', () => this.linkClick());
  }
  // methods
  linkClick() {
    this.content. toggleContent();
  }
} // link
class Content {
  constructor(content) {
    this. contentTab = content;
  }
  // Methods
  toggleContent() {
    this.contentTab. classList.toggle('change');
  }
}
//Step 1: Get our DOM elements and store them in links
const links = document. querySelectorAll('.link');
// Step 2: Iterate over the NodeList and create a new object
links. forEach(function(link){
  // we are returning our newly created objects here
  return new Link(link);
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Kann man in HTML custon data attributes einfügen?

A

-Ja, mit

<div class="school">Lambda School</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Sind custom data attributes in HTML wie hier eingefügt Klassen?

<div>Lambda School</div>

A

Nein!

-Es sind data attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ist die 1 im data attribute data-tab hier ein String oder eine Nummer?

<div>Tab 1</div>

A

-Ein String!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Wozu und wie werden data attributes in HTML verwendet?

A
  • Um die HTML Elemente mit JavaScript anzusprechen

- Sind von der Spezifizität zwischen Klassen (unspezifisch, viele Elemente) und IDs (sehr spezifisch nur ein Element)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Wie heißt das folgende data attribute eines HTML Elementes und wie greift man mit JavaScript darauf zu`?

<div>Lambda School</div>

A

-Das Data Attribut heißt “school”

const school = document.querySelector('.school');
  const schoolName = school.dataset.school;
  console.log(schoolName); //Lambda
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Womit started jedes data attribut in HTML?

A

Mit:

data-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

WIe kann man verschiene HTML Elemente über data attributes miteinander verbinden?

A

-Indem man ihnen die gleichen data attributes zuweist

      <div class="tab-links">
        <div class="link">Tab 1</div>
        <div class="link">Tab 2</div>
        <div class="link">Tab 3</div>
        <div class="link">Tab 4</div>
      </div>
      <div class="tab-contents">
        <div class="content">Tab 1</div>
        <div class="content">Tab 2</div>
        <div class="content">Tab 3</div>
        <div class="content">Tab 4</div>
      </div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Wie kann man den Zugriff auf data attributes dynamisch über mehrere namen/Zahlen machen?

A
  • Mit String Interpolation

this. content = document.querySelector(.content[data-tab='${this.link.dataset.tab}']);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Wie kann man einen Toggle für ein Klassen Object eins DOMs bauen?

A
class Content {
  constructor(content) {
    this. contentTab = content;
  }
  // Methods
  toggleContent() {
    this. contentTab.classList. toggle('change');
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly