1 year ago

#387417

test-img

Phong Hoang

Multiple buttons function to expand and hide div section with javascript

Hope everyone is having fun on this fun (or frustrating ๐Ÿ˜‚ like me) coding day. So, I came across a problem and was hoping someone could help guide me to the right solution. I want to set it so that when I click on the โ€œread moreโ€ button, it adds the โ€œactiveโ€ class and would expand the paragraphs. I was able to do a loop function for multiple buttons on the page, but when I click on one, it affects all the buttons. I know this is a looping problem but I have not figured out a way to solve it. What Iโ€™m trying to do is basically only have the button I click on add the class, without it working on all the buttons on the webpage. I intend to add more buttons to the page, so if anyone has a better solution or knows of a looping method (cause Iโ€™m pretty sure the looping Iโ€™m using is the wrong way), please help. Please see the video for what I mean when I click on one button, both buttons get affected by it.

javascript

button

foreach

hidden-field

0 Answers

Your Answer

Accepted video resources