this might be kind of a basic question, but I can’t solve the problem:
I have multiple elements which are dynamic. Each element should have a visibility toggle Button. How do I do that? Obviously right now, only the excerpt of the first element will be toggled.
I guess it can work with <?= $data->id() ?>, but I don’t know how to tell jQuery, that it should address the specific id.
Hi there,
the main problem is that you are working with ID’s. An ID should be unique, just change them to classes. You will see that now all job-excerpts will toggle when you click a button. So you have to go through your DOM to find the right element (Tree Traversal | jQuery API Documentation). The final code should look something like this in your loop:
I’m sorry, but I have a similar problem as well. I have a homepage that contains information populated by different pages. I have “read more” and “read less” as a general idea—the hope is that the viewer can press “read more” and expand the content individually.
Currently, the jquery is like this, but of course, it ends up expanding everything at once instead of just the section the “read more button” is under.