Skip to content
Open
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
10 changes: 9 additions & 1 deletion 01/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
console.log('DOM');
console.log('DOM');


const element = document.querySelector('.comments__item.comments__item--newest');

if (element) {
const count1 = element.querySelectorAll('[data-info]').length;
console.log(count1)
};
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.

👍

8 changes: 7 additions & 1 deletion 02/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
console.log('DOM');
console.log('DOM');

aList = document.querySelectorAll('[data-url]');

aList.forEach(element => {
element.setAttribute('href', element.dataset.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.

👍

20 changes: 19 additions & 1 deletion 03/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
console.log('DOM');
const parent = document.querySelector('.parent-for-button')

const buttonSettings = {
attr: {
Expand All @@ -11,4 +12,21 @@ const buttonSettings = {
color: '#444'
},
text: 'Click me!',
}
};

const newBtn = document.createElement("button");
newBtn.innerText = buttonSettings.text;

for (const key in buttonSettings.css) {
newBtn.style[key] = buttonSettings.css[key];
};

for (const key in buttonSettings.attr) {
if (key === "className") {
newBtn.className = buttonSettings.attr.className;
} else {
newBtn.setAttribute(key, buttonSettings.attr[key]);
}
Comment on lines +25 to +29
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.

Można też tak: newBtn[key] = buttonSettings.attr[key] - bez if :)

};

parent.appendChild(newBtn);
32 changes: 28 additions & 4 deletions 04/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,31 @@ console.log('DOM');

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

const nav = document.querySelector("nav")
const menu1 = document.createElement("ul")
const menu2 = document.createElement("ul")

// Struktura innerHTML

menu1.innerHTML = "<li><a href='/'>home</a></li><li><a href='/gallery'>gallery</a></li><li><a href='/contact'>contact</a></li>";

nav.appendChild(menu1);

// Pętla

menuItems.forEach(function (e) {
const li = document.createElement('li');
const a = document.createElement('a');

a.innerText = e.text;
a.setAttribute("href", e.url);

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

nav.appendChild(menu2);
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.

👍

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

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

const parent = curr.parentElement;
const parentChildrenList = parent.children;
const parentSibling = parent.nextElementSibling;
const parentOfParent = parent.parentElement;
const lastParent0fParentChild = parentOfParent.lastElementChild;
const lastParent0fParentChildButton = lastParent0fParentChild.lastElementChild;

const newBtn = document.createElement('button');
const newP = document.createElement('p');
newP.innerText = "Lorem Ipsum";
newBtn.innerText = 'Usuń z koszyka';

parent.appendChild(newBtn);

for (const child of parentChildrenList) {
if (child !== curr) {
child.classList.add("siblings");
};
};

parentSibling.setAttribute('title', 'nextElementSibling');

lastParent0fParentChild.insertBefore(newP, lastParent0fParentChildButton);


createArticle();

function createArticle(title = "Default Title") {

const articleStructure = {
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.

Chyba łatwiej by było użyć .cloneNode :)

className: "articles__item article",
content: {
h1: {
className: "article__title",
text: title,
},
p: {
className: "article__description",
text: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur quo quibusdam, nemo neque consequuntur pariatur totam? Facere quaerat molestias hic.",
},
button: {
className: "article__btn",
text: "Kupuję!",
},
},
};


const newArticle = document.createElement("article");

newArticle.className = articleStructure.className;

for (const key in articleStructure.content) {
const newProp = document.createElement(key);

for (const e in articleStructure.content[key]) {
if (e === "className") {
newProp.className = articleStructure.content[key][e];
} else {
newProp.innerText = articleStructure.content[key][e];
}
}

newArticle.appendChild(newProp);
};

parentOfParent.insertBefore(newArticle, parentOfParent.firstElementChild);
};