-
Notifications
You must be signed in to change notification settings - Fork 172
Zadania DOM #145
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?
Zadania DOM #145
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,5 @@ | ||
| console.log('DOM'); | ||
| console.log('DOM'); | ||
| const item = document.querySelector('.comments__item.comments__item--newest'); | ||
| console.log(item); | ||
| const spanList = item.querySelectorAll('[data-info]'); | ||
| console.log(spanList.length); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| console.log('DOM'); | ||
| console.log('DOM'); | ||
| const linkList = document.querySelectorAll('[data-url]'); | ||
| console.log(linkList); | ||
| linkList.forEach(function(item){ | ||
| console.log(item); | ||
| const url = item.getAttribute('data-url') | ||
| item.setAttribute('href', url); | ||
| console.log(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 |
|---|---|---|
|
|
@@ -11,4 +11,23 @@ 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.innerText = buttonSettings.text; | ||
|
|
||
|
|
||
| const parent = document.querySelector('.parent-for-button'); | ||
| parent.appendChild(button); | ||
|
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'); | ||
| /* | ||
| const nav = document.querySelector('nav'); | ||
| const ul = document.createElement('ul'); | ||
| const li1 = document.createElement('li'); | ||
| const a1 = document.createElement('a') | ||
| a1.setAttribute('href','/'); | ||
| a1.innerText = 'start'; | ||
| li1.appendChild(a1); | ||
| ul.appendChild(li1); | ||
| nav.appendChild(ul); | ||
|
|
||
| const li2 = document.createElement('li'); | ||
| const a2 = document.createElement('a'); | ||
| a2.setAttribute('href','/gallery'); | ||
| a2.innerText = 'galeria'; | ||
| ul.appendChild(li2); | ||
| li2.appendChild(a2); | ||
|
|
||
| const li3 = document.createElement('li'); | ||
| const a3 = document.createElement('a'); | ||
| a3.setAttribute('href', '/contact'); | ||
| a3.innerText = 'kontakt'; | ||
| ul.appendChild(li3); | ||
| li3.appendChild(a3); | ||
| */ | ||
| // 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) { | ||
| console.log(item) | ||
| const li = document.createElement('li'); | ||
| const a = document.createElement('a'); | ||
| li.appendChild(a); | ||
| ul.appendChild(li); | ||
| a.setAttribute('href', item.url); | ||
| a.innerText = item.text; | ||
| }); | ||
| nav.appendChild(ul); | ||
|
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,35 @@ | ||
| console.log('DOM'); | ||
|
|
||
| const curr = document.querySelector('.js-curr'); | ||
| // 1. Utwórz kolejny przycisk, który będzie rodzeństwem (bratem) dla elementu ze zmiennej `curr`. Element ten niech zawiera napis `usuń z koszyka`. | ||
| const newButton = document.createElement('button'); | ||
| newButton.innerText = 'usuń z koszyka'; | ||
| curr.parentElement.appendChild(newButton); | ||
| //2. Do wszystkich elementów, które są rodzeństwem elementu o klasie `.js-curr`, dodaj klasę `.siblings` (wykorzystaj pętlę). | ||
| console.log(curr.parentElement.children); | ||
| const children = Array.from(curr.parentElement.children) | ||
| children.forEach(function(child){ | ||
| if(child !== curr) { | ||
| child.classList.add('siblings') | ||
| } | ||
| }) | ||
| curr.parentElement.nextElementSibling.setAttribute('title', 'nextElementSibling'); | ||
| const newPar = document.createElement('p') | ||
| const lastArticle = curr.parentElement.nextElementSibling.nextElementSibling | ||
| lastArticle.insertBefore(newPar, lastArticle.querySelector('p')); | ||
| const firstArticle = document.createElement('article'); | ||
| firstArticle.classList.add('articles.item','article' ); | ||
| const heading = document.createElement('h1'); | ||
| heading.classList.add('article__title'); | ||
| heading.innerText = 'Czy to sie uda?'; | ||
| firstArticle.appendChild(heading); | ||
| const secondPar = document.createElement('p') | ||
| secondPar.classList.add('article__description'); | ||
| secondPar.innerText = 'Zobaczymy' | ||
| firstArticle.appendChild(secondPar); | ||
| const lastButton = document.createElement('button') | ||
| lastButton.classList.add('article__btn'); | ||
| lastButton.innerText = 'Wkrótce'; | ||
| firstArticle.appendChild(lastButton); | ||
| const addArticle = curr.parentElement.parentElement; | ||
| addArticle.insertBefore(firstArticle, addArticle.firstChild); | ||
|
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. 👍 |
||
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.
👍