+ 1

Problem with details with JavaScript

Hello, in this code i have add some JS to hidden the rest of <details> in the page, when click on details the other details are hidden and if click again the rest of details is showed. the problem is after the first click if click in other point of details( for exapmle in the text) the function onclick associated run but the details remain open. i have tried to risolve to add: document.getElementId("details").open= 'true'; document.getElementId("details").open= 'false'; but don't work thanks to those who want to help me https://code.sololearn.com/WLcO7JBeMgHw/#

21st May 2020, 4:35 PM
Alessio Farroni
Alessio Farroni - avatar
9 odpowiedzi
+ 4
See this code :)) https://code.sololearn.com/WltPavNklhI4/?ref=app Click on those titles to open the details :))
21st May 2020, 5:52 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 3
Alessio Farroni Base on what you wanted your code to do, I refactored your script. https://code.sololearn.com/WlUdjbDZoyUJ/#html
21st May 2020, 7:19 PM
ODLNT
ODLNT - avatar
+ 1
David D. I solved After have see your work, thank's ☺️
21st May 2020, 7:09 PM
Alessio Farroni
Alessio Farroni - avatar
+ 1
ODLNT thank you, very nice code. Is very clean and clear. I'll study It😉
21st May 2020, 7:41 PM
Alessio Farroni
Alessio Farroni - avatar
0
Why dont you add another button on the page or part which is opening after clicking button to close it .
21st May 2020, 4:59 PM
Ayush Kumar
Ayush Kumar - avatar
0
🇮🇳 AYUSH.ks 🇮🇳 because the problem will still remain, if clicking on the text, details does'nt close
21st May 2020, 5:08 PM
Alessio Farroni
Alessio Farroni - avatar
0
David D. Thank you, I was thinking to throw away my computer 😆 ...however I still think where the problem is and how to solve it
21st May 2020, 5:16 PM
Alessio Farroni
Alessio Farroni - avatar
0
David D. When its clicked on the text(<p>) of the opened details it has to be closed so that the user has the oportunity to open another details Thank you so much for helping☺️
21st May 2020, 5:33 PM
Alessio Farroni
Alessio Farroni - avatar
0
thank you all for your help I solved it by assigning onclick to <summary> instead of <div> or <details>
21st May 2020, 6:47 PM
Alessio Farroni
Alessio Farroni - avatar