diff --git a/01/app.js b/01/app.js index 1c9992e..b21d0be 100644 --- a/01/app.js +++ b/01/app.js @@ -1 +1,10 @@ -console.log('DOM'); \ No newline at end of file +const elementList = document.querySelector('.comments__item.comments__item--newest'); + +if (elementList !== null){ // Wykonuje tylko wtedy kiedy element został znaleziony + + const elementNewest = elementList.querySelectorAll('[data-info'); + + console.log(`Wszystkich elementów posiadających atrybut "data-info" oraz dwie klasy (comments__item, comments__item--newest) jest ${elementNewest.length}.`); // lenght - ilość elementów w tablicy zwrucona wartość to obiekt typu NodeList str. 22 +} else{ + console.log('Elementów które posiadają atrybut "data-info" NIE ZNALEZIONO'); +} diff --git a/02/app.js b/02/app.js index 1c9992e..ebfe374 100644 --- a/02/app.js +++ b/02/app.js @@ -1 +1,21 @@ -console.log('DOM'); \ No newline at end of file +const linkaDataUrl = document.querySelectorAll('a[data-url]'); // a z data-url + +linkaDataUrl.forEach(link => { + + const dataAUrl = link.getAttribute('data-url'); + + if(dataAUrl){ + link.setAttribute('href', dataAUrl); + link.removeAttribute('data-url'); // usuwam data-url + } + + const href = link.getAttribute('href'); + + try { + new URL(href); // Jeśli nieprawidłowy – wyrzuci wyjątek + console.log(`Poprawne linkpwanie: ${href}`); + } catch (error) { + console.warn(`Niepoprawne linkowanie: ${href}`); + link.textContent += ' X'; + } +}); \ No newline at end of file diff --git a/02/index.html b/02/index.html index 89a53f6..7572329 100644 --- a/02/index.html +++ b/02/index.html @@ -13,8 +13,8 @@