-
Notifications
You must be signed in to change notification settings - Fork 172
resolved exervises - js-dom-elements #148
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
9cd7edf
eefeec1
dbe0fb8
52f4936
fe0321d
80f84e4
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,12 @@ | ||
| console.log('DOM'); | ||
| console.log('DOM'); | ||
|
|
||
| const element = document.querySelector('.comments__item.comments__item--newest'); | ||
|
|
||
| if (element){ | ||
| const elementsWithAtribute = element.querySelectorAll('[data-info]'); | ||
| console.log(elementsWithAtribute); | ||
| console.log(`Znaleziono ${elementsWithAtribute.length} elementy z podanym atrybutem`); | ||
|
|
||
| } else { | ||
| console.log(`Nie znaleziono elementu o podanej klasie`); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,10 @@ | ||
| console.log('DOM'); | ||
| console.log('DOM'); | ||
|
|
||
| const linksWithUrl = document.querySelectorAll('[data-url]'); | ||
| console.log(linksWithUrl); | ||
|
|
||
|
|
||
| linksWithUrl.forEach((element) => { | ||
| const elementUrl = element.getAttribute('data-url'); | ||
| element.setAttribute('href', elementUrl) | ||
| }) | ||
|
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,18 @@ const buttonSettings = { | |
| color: '#444' | ||
| }, | ||
| text: 'Click me!', | ||
| } | ||
| } | ||
|
|
||
| const newButton = document.createElement('button'); | ||
| for (const property in buttonSettings.attr){ | ||
| newButton.setAttribute(property, buttonSettings.attr[property]); | ||
| } | ||
|
|
||
| for (const property in buttonSettings.css){ | ||
| newButton.style[property] = buttonSettings.css[property]; | ||
| } | ||
|
|
||
| newButton.textContent = buttonSettings.text; | ||
|
|
||
| const element = document.querySelector('.parent-for-button'); | ||
| element.appendChild(newButton); | ||
|
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 |
|---|---|---|
|
|
@@ -5,4 +5,34 @@ const menuItems = [ | |
| {text: 'start', url: '/'}, | ||
| {text: 'galeria', url: '/gallery'}, | ||
| {text: 'kontakt', url: '/contact'}, | ||
| ]; | ||
| ]; | ||
|
|
||
|
|
||
| // const navElement = document.querySelector('nav'); | ||
|
|
||
| // if (navElement){ | ||
| // const ulElement = document.createElement('ul'); | ||
| // navElement.appendChild(ulElement); | ||
| // } | ||
|
|
||
| // const ulElement = document.querySelector('ul'); | ||
| // if(ulElement){ | ||
| // const liElement1 = document.createElement('li'); | ||
| // const liElement2 = document.createElement('li'); | ||
| // const liElement3 = document.createElement('li'); | ||
| // ulElement.appendChild(liElement1); | ||
| // ulElement.appendChild(liElement2); | ||
| // ulElement.appendChild(liElement3); | ||
| // } | ||
|
|
||
| const navElement = document.querySelector('nav'); | ||
|
|
||
| menuItems.forEach((el => { | ||
| const liElement = document.createElement('li'); | ||
| const aElement = document.createElement('a'); | ||
|
|
||
| aElement.innerText = el.text; | ||
| aElement.setAttribute('href', el.url) | ||
| navElement.appendChild(liElement); | ||
| liElement.appendChild(aElement); | ||
| })) | ||
|
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,50 @@ | ||
| console.log('DOM'); | ||
|
|
||
| const curr = document.querySelector('.js-curr'); | ||
|
|
||
| // 1 | ||
| const currParent = curr.parentElement; | ||
| const newButton = document.createElement('button'); | ||
| newButton.innerText = 'usuń z koszyka' | ||
| currParent.appendChild(newButton); | ||
|
|
||
| // 2 | ||
| const currSiblings = Array.from(currParent.children); | ||
| currSiblings.filter((el) => !el.classList.contains('js-curr')).forEach(el => el.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. 👍 |
||
|
|
||
| // 3 | ||
| currParent.nextElementSibling.setAttribute('title', 'nextElementSibling'); | ||
|
|
||
| // 4 | ||
| const lastSibling = currParent.parentElement.lastElementChild; | ||
| const pElement = document.createElement('p'); | ||
|
|
||
| lastSibling.insertBefore(pElement, lastSibling.lastElementChild); | ||
|
|
||
|
|
||
| // 5 | ||
| const newArticle = document.createElement('article'); | ||
|
|
||
| const articles = currParent.parentElement; | ||
| console.log(articles); | ||
|
|
||
| articles.insertBefore(newArticle, currParent); | ||
| newArticle.classList.add('articles__item', 'article'); | ||
|
|
||
| const newTitle = document.createElement('h1') | ||
| const newParagraph = document.createElement('p'); | ||
| const newBtn = document.createElement('button'); | ||
|
|
||
| newTitle.innerText = 'JS - New Article'; | ||
| newParagraph.innerText = 'Lorem test'; | ||
| newBtn.innerText = 'new btn' | ||
|
|
||
| newTitle.classList.add('article__title'); | ||
| newParagraph.classList.add('article__description'); | ||
| newBtn.classList.add('article__btn'); | ||
|
|
||
| newArticle.appendChild(newTitle); | ||
| newArticle.appendChild(newParagraph); | ||
| newArticle.appendChild(newBtn); | ||
|
|
||
|
|
||
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.
👍