jQuery toggle on a PHP foreach statement

Posted by user313835 on Stack Overflow See other posts from Stack Overflow or by user313835
Published on 2010-04-11T09:41:13Z Indexed on 2010/04/11 9:53 UTC
Read the original article Hit count: 220

Filed under:
|
|
|

The code for the page is the following

<?php foreach ($organization->index() as $id=>$content) { ?>
<a href="#" id="obtain_branch"><?= $content->name?></a>
<div id="directory_brnach"><?= $content->about?></div>
<?php } ?>

The JavaScript code using jQuery is

 // Directory inner branches
$('#obtain_branch').click(function(){
   $('#directory_brnach').toggle('fast');
});

The problem it will only work on the first one given the the ID is not changing, the rest will not change.

How can I send an array to the jQuery function to give an individual ID on every iteration?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery