PHP and jQuery

PHP and jQuery

Well, I have a table that is being created  dynamically out of mysql data depending on the GET parameters that are being passed. I would like to 'inject' some jquery via PHP's echoes into the same page that will add some event handlers when each row is being clicked.


gives me the next table - 

  1. <table>
  2. <tr><td>
  3. <div class=<?php echo $_GET['name'].'1'; ?>> Some data here within a class 'danny1' </div> </td>
  4. <td> Another data here </td></tr>
  5. <tr><td>
  6. <div class=<?php echo $_GET['name'].'2'; ?>> Another new line here with the class 'danny2' </div></td>
  7. </tr>
  8. </table>

^ its just an example of a code for a better understading, not the real one of course, so you can see that each <tr> is being created dynamically with a div inside of it called danny1,danny2, and so on..

so my question is - how can i add dynamically handlers for each of these lines (using their class name and not implementing the handlers on <tr>'s in general) that when i click on them they'll be animated (slided to top), like -

  1.     
    $( "#danny1" ).click(function() {
    $( "#danny1" ).slideToggle( "slow" );
    });

but the problem is that 'danny1' doesn't really exist before the page is really created so i though about adding a little piece of jquery inside the PHP's loop to attach 1 custom handler to each <div>, like this :

  1.       
    echo '$( '.$_GET['name'].'1 ).click(function() {
    $( '.$_GET['name'].'1 ).slideToggle( "slow" );
    });';
but for some reason it doesn't really create those pieces of code when i view source of page, and even if it would work, this one looks like a messy solution for me.

any suggestions?

(by the way - all of this used on wordpress so $() was replaced with jQuery() - if it changes anything..)