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
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');
console.log("DOM");

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

if (element) {
const elementsInfoList = element.querySelectorAll(`*[data-info]`);

console.log(`Found: ${elementsInfoList.length} elements`);
}
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.

👍

53 changes: 36 additions & 17 deletions 01/index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="Mateusz Bogolubow">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<meta name="author" content="Mateusz Bogolubow" />
<title>devmentor.pl - JS DOM Elements - #01</title>
</head>
<body>
</head>
<body>
<ul class="comments">
<li class="comments__item comments__item--newest">
<p>Lorem ipsum <span data-info="https://devmentor.pl">dolor</span> sit amet consectetur adipisicing elit. Iure, vero! <span data-info="https://devmentor.pl">Lorem</span> ipsum dolor sit amet, consectetur adipisicing elit. Nobis, amet?</p>
<p>Lorem ipsum dolor sit amet consectetur, <span data-info="https://devmentor.pl">adipisicing</span> elit. Magnam temporibus necessitatibus repellendus! Earum fugit distinctio facere iusto nesciunt! Voluptatem, perspiciatis?</p>
</li>
<li class class="comments__item">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. <span data-info="https://devmentor.pl">Iure</span>, vero! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis, amet?</p>
<p>Lorem ipsum dolor <span data-info="https://devmentor.pl">sit</span> amet consectetur, adipisicing elit. Magnam temporibus necessitatibus repellendus! Earum fugit distinctio facere iusto nesciunt! Voluptatem, perspiciatis?</p>
</li>
<li class="comments__item comments__item--newest">
<p>
Lorem ipsum <span data-info="https://devmentor.pl">dolor</span> sit
amet consectetur adipisicing elit. Iure, vero!
<span data-info="https://devmentor.pl">Lorem</span> ipsum dolor sit
amet, consectetur adipisicing elit. Nobis, amet?
</p>
<p>
Lorem ipsum dolor sit amet consectetur,
<span data-info="https://devmentor.pl">adipisicing</span> elit. Magnam
temporibus necessitatibus repellendus! Earum fugit distinctio facere
iusto nesciunt! Voluptatem, perspiciatis?
</p>
</li>
<li class class="comments__item">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
<span data-info="https://devmentor.pl">Iure</span>, vero! Lorem ipsum
dolor sit amet, consectetur adipisicing elit. Nobis, amet?
</p>
<p>
Lorem ipsum dolor
<span data-info="https://devmentor.pl">sit</span> amet consectetur,
adipisicing elit. Magnam temporibus necessitatibus repellendus! Earum
fugit distinctio facere iusto nesciunt! Voluptatem, perspiciatis?
</p>
</li>
</ul>

<script src="./app.js"></script>
</body>
</html>
</body>
</html>
9 changes: 8 additions & 1 deletion 02/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
console.log('DOM');
console.log("DOM");

const linksList = document.querySelectorAll("a[data-url]");

linksList.forEach((link) => {
const href = link.dataset.url;
link.setAttribute("href", href);
});
38 changes: 26 additions & 12 deletions 03/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
console.log('DOM');
console.log("DOM");

const buttonSettings = {
attr: {
className: 'btn',
title: 'super button'
},
css: {
border: '1px solid #336699',
padding: '5px 20px',
color: '#444'
},
text: 'Click me!',
}
attr: {
className: "btn",
title: "super button",
},
css: {
border: "1px solid #336699",
padding: "5px 20px",
color: "#444",
},
text: "Click me!",
};

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

for (const propety in buttonSettings.attr) {
button.setAttribute(propety, buttonSettings.attr[propety]);
}

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

const parent = document.querySelector(".parent-for-button");
if (parent) parent.appendChild(button);
26 changes: 21 additions & 5 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
console.log('DOM');
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 menuElement = document.createElement("ul");

menuItems.forEach((item) => {
const itemElement = document.createElement("li");

const linkElement = document.createElement("a");
linkElement.setAttribute("href", item.url);
linkElement.textContent = item.text;

itemElement.appendChild(linkElement);
menuElement.appendChild(itemElement);
});

const navigationElement = document.querySelector("nav");
if (navigationElement) navigationElement.appendChild(menuElement);
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.

👍

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

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

if (curr) {
// Task 1
const newButtonEl = document.createElement("button");
newButtonEl.textContent = "Usun z koszyka";

curr.parentElement.appendChild(newButtonEl);

// 2
Array.from(curr.parentElement.children).forEach((child) => {
if (child === curr) return;
child.classList.add("siblings");
});

// 3
const articleEl = curr.parentElement.nextElementSibling;
if (articleEl) articleEl.setAttribute("title", "nextElementSibling");

// 4
const lastArticleEl = curr.parentElement.parentElement.lastElementChild;
if (lastArticleEl && lastArticleEl.tagName === "ARTICLE") {
const buttonEl = lastArticleEl.querySelector("button");

if (buttonEl) {
const newParagraphEl = document.createElement("p");
newParagraphEl.textContent = "Additional paragraph";
lastArticleEl.insertBefore(newParagraphEl, buttonEl);
}
}

// 5
const sectionEl = curr.parentElement.parentElement;
if (sectionEl && sectionEl.tagName === "SECTION") {
const newArticle = document.createElement("article");
newArticle.className = "articles__item article";

const heading = document.createElement("h1");
heading.classList.add("article__title");
heading.textContent = "Heading";

const paragraph = document.createElement("p");
paragraph.classList.add("article__description");
paragraph.textContent = "Paragraph";

const button = document.createElement("button");
button.classList.add("article__button");
button.textContent = "Kupuje!";

newArticle.appendChild(heading);
newArticle.appendChild(paragraph);
newArticle.appendChild(button);

const firstArticle = sectionEl.firstChild;
sectionEl.insertBefore(newArticle, firstArticle);
}
}