From 13d247a813f339e71b436353ceab60b3faf9c11d Mon Sep 17 00:00:00 2001 From: Marek Oleksik <45736363+MarekOleksik@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:40:37 +0200 Subject: [PATCH] added code to task 2 as required in readme --- 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(); + }); + } + }); +});