help to reiterate through my jquery snippet

Posted by s2xi on Stack Overflow See other posts from Stack Overflow or by s2xi
Published on 2010-12-30T22:43:57Z Indexed on 2010/12/30 22:54 UTC
Read the original article Hit count: 178

Filed under:

Code in question:

$("#alpha").click(function(event) {
    event.preventDefault();
    $("#show").slideToggle();
});

I have a list of files and its being outputted with PHP in alphabetical. I use this method in PHP:

foreach(range('A','Z') as $i) {
    if (array_key_exists ("$i", $alpha)) {
        echo '<div id="alpha"><a href="#" name="'.$i.'"><h2>'.$i.'</h2></a></div><div id="show">';
        foreach ($$i as $key=>$value)
            echo '<p>'.$value.' '.$key.'</p>';
    }
    echo '</div>';
}

What I want to do is when the user clicks on the #alpha to toggle the div #show that has the names that belong to a letter up. I can do this with the first listing, but every listing after that isn't affected.

how can i tell jquery that foreach letter apply the js code so it can toggle up/down the #show.

I don't want to this 26 times (one time for each letter in the alphabet), I tried to use class instead of id but that causes all the #show to toggleup heh.

© Stack Overflow or respective owner

Related posts about jQuery