From 6ca607911ceeae3b517187bf71f673b6679dc093 Mon Sep 17 00:00:00 2001 From: Goutham <33145049+GouthamShiv@users.noreply.github.com> Date: Wed, 2 Feb 2022 14:26:20 +0530 Subject: [PATCH] update to feedback selection clicking the feedback text was throwing console log, so, updated logic to consider the feedback text for selection --- feedback-ui-design/script.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/feedback-ui-design/script.js b/feedback-ui-design/script.js index b3eb3fd..1b758c5 100644 --- a/feedback-ui-design/script.js +++ b/feedback-ui-design/script.js @@ -5,15 +5,18 @@ const panel = document.querySelector('#panel') let selectedRating = 'Satisfied' ratingsContainer.addEventListener('click', (e) => { - if(e.target.parentNode.classList.contains('rating')) { + if(e.target.parentNode.classList.contains('rating') && e.target.nextElementSibling) { removeActive() e.target.parentNode.classList.add('active') selectedRating = e.target.nextElementSibling.innerHTML - } - if(e.target.classList.contains('rating')) { + } else if( + e.target.parentNode.classList.contains('rating') && + e.target.previousSibling && + e.target.previousElementSibling.nodeName === 'IMG' + ) { removeActive() - e.target.classList.add('active') - selectedRating = e.target.nextElementSibling.innerHTML + e.target.parentNode.classList.add('active') + selectedRating = e.target.innerHTML } }) @@ -32,4 +35,4 @@ function removeActive() { for(let i = 0; i < ratings.length; i++) { ratings[i].classList.remove('active') } -} \ No newline at end of file +}