Better ideas on how to Assigning Id dynamically in Javascript and PHP
<p>A lot of my PHP code creates a dynamic ID selector because I don't have the ID <code>attr</code> value until I execute the PHP code, so I am finding myself taking a shortcut and putting jquery javascript code as name of the ID being created. </p>

<p>So I want to know if there are other ways of doing it better. My current method works, but I know it's bad practice.</p>

<p>To illustrate what I am doing:</p>

<pre><code>for ($x=0;$x&gt;=10; $x++){
echo "...
    &lt;script&gt;
    $(function() {
    $( \"#dialog{$x}\" ).dialog({
        autoOpen: false,
        show: \"blind\",
        hide: \"explode\"
    });
    $( \"#opener{$x}\" ).click(function() {
      $( \"#dialog{$x}\" ).dialog( \"open\" );
        return false;
    });
    &lt;/script&gt;
    ...";


  echo "&lt;a id=\"opener{$x}\"&gt; View Notes&lt;/a&gt;";
  echo "&lt;div id=\"dialog{$x}\"&gt;some data also dynamically generated depending on value of $x&lt;/div&gt;";
}
</code></pre>
