Skip to content
Open

Done #149

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 01/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
console.log('DOM');

const liElement = document.querySelector('.comments__item.comments__item--newest');
const dataInfoList = liElement.querySelectorAll('[data-info]');

if(liElement && dataInfoList) {
console.log(`Znaleziono ${dataInfoList.length} poniższe elementy z atrybutem data-info :`);
Comment on lines +3 to +6
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tutaj mamy drobny błąd logiczny - sprawdzasz czy element został wyszukany później niż go wykorzystujesz.
Powinno być:

const liElement = document.querySelector('.comments__item.comments__item--newest');
if(liElement) {
    const dataInfoList = liElement.querySelectorAll('[data-info]');
    console.log(`Znaleziono ${dataInfoList.length} poniższe elementy z atrybutem  data-info :`);
}

Nie trzeba sprawdzać dataInfoList bo to tablica elementów więc nieważne czy jest ich 0 czy więcej to błędu nie będzie.


dataInfoList.forEach(function(element) {
console.log(element)
});
}
11 changes: 10 additions & 1 deletion 02/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
console.log('DOM');
const linkList = document.querySelectorAll('[data-url')

linkList.forEach(function(link) {
const url = link.getAttribute('data-url');

if(url) {
link.setAttribute('href', url)
}
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

16 changes: 16 additions & 0 deletions 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ const buttonSettings = {
color: '#444'
},
text: 'Click me!',
}

const button = document.createElement('button');

for (const attr in buttonSettings.attr) {
button[attr] = buttonSettings.attr[attr];
}
for (const style in buttonSettings.css) {
button.style[style] = buttonSettings.css[style];
}

button.textContent = buttonSettings.text;

const parentButton = document.querySelector('.parent-for-button');
if (parentButton) {
parentButton.appendChild(button);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
20 changes: 18 additions & 2 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
console.log('DOM');

// struktura do wykorzystania w pętli
const menuItems = [
{text: 'start', url: '/'},
{text: 'galeria', url: '/gallery'},
{text: 'kontakt', url: '/contact'},
];
];

const nav = document.querySelector('nav');
const ul = document.createElement('ul');



menuItems.forEach(function(item) {
const li = document.createElement('li');
const a = document.createElement('a');
a.href = item.url;
a.textContent = item.text;

li.appendChild(a);
ul.appendChild(li);
});

nav.appendChild(ul);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

46 changes: 44 additions & 2 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
console.log('DOM');

const curr = document.querySelector('.js-curr');

//
const newButton = document.createElement('button');
newButton.classList.add('article__btn');
newButton.textContent = 'usuń z koszyka'

curr.parentElement.insertBefore(newButton, curr.nextElementSibling);


//
let sibling = curr.parentElement.firstElementChild;
while (sibling) {
if (sibling !== curr) {
sibling.classList.add('siblings');
}
sibling = sibling.nextElementSibling;
}


//
const nextArticle = curr.closest('.article').nextElementSibling;
if(nextArticle && nextArticle.classList.contains('article')) {
nextArticle.setAttribute('title', 'nextElementSibling');
}


//
const lastArticle = document.querySelector('.articles__item:last-child');
const paragraph = document.createElement('p');
paragraph.textContent = 'Dodskowy paragraf.';
const button = lastArticle.querySelector('.article__btn');
lastArticle.insertBefore(paragraph, button);

//
const newArticle = document.createElement('article');
newArticle.classList.add('articles__item', 'article');
const articlesSection = document.querySelector('.articles');
articlesSection.insertBefore(newArticle, articlesSection.firstElementChild);

newArticle.innerHTML = `
<h1 class="article__title">JS- Nowy Artykuł</h1>
<p class="article__description">Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur quo quibusdam, nemo neque consequuntur pariatur totam? Facere quaerat molestias hic.</p>
<button class="article__btn">Kupuję!</button>
`;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍