-
Notifications
You must be signed in to change notification settings - Fork 172
Completed tasks: practice JS DOM elements #161
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 all commits
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,10 @@ | ||
| console.log('DOM'); | ||
| console.log("DOM"); | ||
|
|
||
| const element = document.querySelector( | ||
| ".comments__item.comments__item--newest" | ||
| ); | ||
|
|
||
| if (element) { | ||
| const dataSetElement = element.querySelectorAll("[data-info]"); | ||
| console.log(dataSetElement.length); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| console.log('DOM'); | ||
| console.log("DOM"); | ||
|
|
||
| const dataUrl = document.querySelectorAll("[data-url"); | ||
| dataUrl.forEach(function (el) { | ||
| const url = el.dataset.url; | ||
| if (!el.hasAttribute("href")) { | ||
| el.setAttribute("href", url); | ||
| } | ||
| }); | ||
|
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,20 +1,24 @@ | ||
| <!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 - #02</title> | ||
| </head> | ||
| <body> | ||
| </head> | ||
| <body> | ||
| <h1>Moje ulubione strony:</h1> | ||
| <ul> | ||
| <li><a data-url="https://devmentor.pl">devmentor.pl</a></li> | ||
| <li><a data-url="https://developer.mozilla.org/pl/">eveloper.mozilla.org</a></li> | ||
| <li><a data-url="https://stackoverflow.com">stackoverflow.com</a></li> | ||
| <li><a>null</a></li> | ||
| <li><a data-url="https://devmentor.pl">devmentor.pl</a></li> | ||
| <li> | ||
| <a data-url="https://developer.mozilla.org/pl/" | ||
| >developer.mozilla.org</a | ||
| > | ||
| </li> | ||
| <li><a data-url="https://stackoverflow.com">stackoverflow.com</a></li> | ||
| <li><a>null</a></li> | ||
| </ul> | ||
| <script src="./app.js"></script> | ||
| </body> | ||
| </html> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,31 @@ | ||
| 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 buttonParent = document.querySelector(".parent-for-button"); | ||
| const btn = document.createElement("button"); | ||
| const buttonText = document.createTextNode(buttonSettings.text); | ||
| buttonParent.appendChild(btn); | ||
|
|
||
| if (btn) { | ||
| btn.appendChild(buttonText); | ||
| for (const property in buttonSettings.attr) { | ||
| btn.setAttribute(property, buttonSettings.attr[property]); | ||
| } | ||
|
|
||
| for (const cssProperty in buttonSettings.css) { | ||
| console.log(cssProperty); | ||
| btn.style.setProperty(cssProperty, buttonSettings.css[cssProperty]); | ||
| } | ||
| } | ||
|
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,8 +1,44 @@ | ||
| 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 ulElement = document.createElement("ul"); | ||
| const navElement = document.querySelector("nav"); | ||
| navElement.appendChild(ulElement); | ||
|
|
||
| // Rozwiązanie bez tablicy | ||
| for (let i = 0; i < 3; i++) { | ||
| const newLiElement = document.createElement("li"); | ||
| const newLinkElement = document.createElement("a"); | ||
| ulElement.appendChild(newLiElement); | ||
| newLiElement.appendChild(newLinkElement); | ||
| if (i === 0) { | ||
| const firstTextNode = document.createTextNode("start"); | ||
| newLinkElement.appendChild(firstTextNode); | ||
| newLinkElement.setAttribute("href", "/"); | ||
| } else if (i === 1) { | ||
| const secondTextNode = document.createTextNode("galeria"); | ||
| newLinkElement.appendChild(secondTextNode); | ||
| newLinkElement.setAttribute("href", "/gallery"); | ||
| } else if (i === 2) { | ||
| const thirdTextNode = document.createTextNode("kontakt"); | ||
| newLinkElement.appendChild(thirdTextNode); | ||
| newLinkElement.setAttribute("href", "/contact"); | ||
| } | ||
| } | ||
|
|
||
| // Rozwiązanie z tablicą | ||
|
|
||
| menuItems.forEach(function (obj) { | ||
| const newLiElement = document.createElement("li"); | ||
| const newLinkElement = document.createElement("a"); | ||
| ulElement.appendChild(newLiElement); | ||
| newLiElement.appendChild(newLinkElement); | ||
| newLinkElement.append(obj.text); | ||
| newLinkElement.setAttribute("href", obj.url); | ||
| }); | ||
|
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,29 @@ | ||
| console.log('DOM'); | ||
| console.log("DOM"); | ||
|
|
||
| const curr = document.querySelector('.js-curr'); | ||
| const curr = document.querySelector(".js-curr"); | ||
| const removeBtn = document.createElement("button"); | ||
| const currParent = curr.parentElement; | ||
|
|
||
| currParent.appendChild(removeBtn); | ||
| const removeBtnText = document.createTextNode("Usuń z koszyka"); | ||
| removeBtn.appendChild(removeBtnText); | ||
|
|
||
| const siblings = currParent.children; | ||
| const siblingsArray = [...siblings]; | ||
|
|
||
| siblingsArray.forEach(function (el) { | ||
| if (!el.classList.contains("js-curr")) { | ||
| el.classList.add("sibling"); | ||
| } | ||
| }); | ||
| if (currParent.nextElementSibling.classList.contains("article")) { | ||
| currParent.nextElementSibling.setAttribute("title", "nextElementSibling"); | ||
| } | ||
|
|
||
| const articleParrent = currParent.parentElement; | ||
| const p = document.createElement("p"); | ||
| const lastBtn = articleParrent.lastElementChild.lastElementChild; | ||
| articleParrent.lastElementChild.insertBefore(p, lastBtn); | ||
|
|
||
| const clonedArticle = currParent.cloneNode(true); | ||
| articleParrent.insertBefore(clonedArticle, currParent); | ||
|
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,30 +1,42 @@ | ||
| <!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 - #05</title> | ||
| </head> | ||
| <body> | ||
| </head> | ||
| <body> | ||
| <section class="articles"> | ||
| <article class="articles__item article"> | ||
| <h1 class="article__title">JS - Elementy DOM</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 js-curr">Kupuję!</button> | ||
| </article> | ||
| <article class="articles__item article"> | ||
| <h1 class="article__title">JS - Zdarzenia</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> | ||
| </article> | ||
| <article class="articles__item article"> | ||
| <h1 class="article__title">JS - Formularze</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> | ||
| </article> | ||
| <article class="articles__item article"> | ||
| <h1 class="article__title">JS - Elementy DOM</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 js-curr">Kupuję!</button> | ||
| </article> | ||
| <article class="articles__item article"> | ||
| <h1 class="article__title">JS - Zdarzenia</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> | ||
| </article> | ||
| <article class="articles__item article"> | ||
| <h1 class="article__title">JS - Formularze</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> | ||
| </article> | ||
| </section> | ||
| <script src="./app.js"></script> | ||
| </body> | ||
| </body> | ||
| </html> |
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.
👍