I needed this question because of I have a hierarchal menu list script maintained by jQuery for hide and display menu's elements in a PHP script. However, in some pages of the script, I have to deal with two menus. The menu skeleton is included in div with id = treeList, so selecting elements with the same id value should halt jQuery selecting, so I needed to dynamically change the id value with some suffix and then by some way set its css to be equaled to the #treeList set in the CSS file.
However, I followed the approach of adding class attribute to the the div id #treeList and instead of selecting the div with the id alone I selected it using both id and class name, while class name is dynamically generated by the PHP as follows:
<?php $suffix = rand(1,1000); ?>
$('#treeList.<?php echo 'c'.$suffix;?>');
<div id="treeList" class="<?php echo 'c'.$suffix;?>">