I am trying to show/hide divs with button click. I couldn't find something that works. I know how to do it with jquery but I have to use javascript for this one. What I tried is below
Section 1
Section 2
Section 3
Section 4
Section 5
Section 6
Section 7

Naimish MakwanaPosted Feb 9, 2023, 6:51 AM
Hello Marius,
Change script code as below:
Thanks
Naimish Makwana
Marius VasilePosted Feb 9, 2023, 7:47 AM
Thank you Naimish that did the trick
Muhammad Imran AnsariPosted Feb 9, 2023, 7:16 AM
Have you checked my code and fiddle?
Initially all sections are hide and only that section will show which is crosspondent button click.
Marius VasilePosted Feb 9, 2023, 6:26 AM
Thank you both, your code is working fine but hiw do I hide the other sections on button click. Like btn 1 show section 1 and hide all others and so on?
Muhammad Imran AnsariPosted Feb 9, 2023, 5:03 AM
Hi Marius,
You can achive this through 'data-toggle' attribute that specifies the id of the div that it should toggle. The event listener retrieves the 'data-toggle' attribute of the button that was clicked and uses it to find the corresponding div. Here is the code
I have also created a jsFiddle for you click the link to check: https://jsfiddle.net/2eym9jg8/
Naimish MakwanaPosted Feb 9, 2023, 4:02 AM
Hello Marius,
Please use below code.
Working Example : https://codepen.io/Naimishcon/pen/abjredx
Thanks
Naimish Makwana