From 2cb5fa7aa520e4b2ab108ad7c58432f127ffbe9a Mon Sep 17 00:00:00 2001 From: Marek Oleksik <45736363+MarekOleksik@users.noreply.github.com> Date: Mon, 16 Sep 2024 08:36:40 +0200 Subject: [PATCH 1/2] added searching elements in dom to app.js --- 01/app.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/01/app.js b/01/app.js index 1c9992ed..41bf4464 100644 --- a/01/app.js +++ b/01/app.js @@ -1 +1,7 @@ -console.log('DOM'); \ No newline at end of file +console.log('DOM'); +const comments = document.querySelector('.comments__item.comments__item--newest'); + +if (comments) { + const elementsWithDataInfo = comments.querySelectorAll('[data-info]'); + console.log('The number of elements that have the attribute data-info:', elementsWithDataInfo.length); +} \ No newline at end of file From 409e6d69e18fbbbcd5b90ede086a05edc5d8b8db Mon Sep 17 00:00:00 2001 From: Marek Oleksik <45736363+MarekOleksik@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:39:03 +0200 Subject: [PATCH 2/2] added Task 02 --- 02/app.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/02/app.js b/02/app.js index 1c9992ed..105c6097 100644 --- a/02/app.js +++ b/02/app.js @@ -1 +1,16 @@ -console.log('DOM'); \ No newline at end of file +document.addEventListener('DOMContentLoaded', function () { + const links = document.querySelectorAll('a[data-url]'); + + links.forEach(link => { + const url = link.getAttribute('data-url'); + + if (url !== 'null') { + link.setAttribute('href', url); + } else { + link.style.color = 'grey'; + link.addEventListener('click', function (event) { + event.preventDefault(); + }); + } + }); +});