-
Notifications
You must be signed in to change notification settings - Fork 172
practice-js-dom-elements #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
42adaa5
ea92b8e
bf20587
329ab34
3eccfaf
c3d8ae4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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`); | ||
| } | ||
| 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,10 @@ | ||
| console.log('DOM'); | ||
| console.log("DOM"); | ||
|
|
||
| const linksList = document.querySelectorAll("a[data-url]"); | ||
|
|
||
| if (linksList) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tutaj |
||
| linksList.forEach((link) => { | ||
| const href = link.dataset.url; | ||
| link.setAttribute("href", href); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,26 @@ | ||
| 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.classList.add(buttonSettings.attr.className); | ||
| button.setAttribute("title", buttonSettings.attr.title); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W przypadku |
||
| button.innerText = buttonSettings.text; | ||
|
|
||
| for (const propety in buttonSettings.css) { | ||
| button.style[propety] = buttonSettings.css[propety]; | ||
| } | ||
|
|
||
| const parent = document.querySelector(".parent-for-button"); | ||
| if (parent) parent.appendChild(button); | ||
| 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,58 @@ | ||
| 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) => | ||
| child.classList.add("siblings") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zwróć uwagę, że |
||
| ); | ||
|
|
||
| // 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); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍