IDは必須ではなく、しばしば有害です。あなたはそれらを生成する必要はありません。
IDを持つページに要素を配置すると、その要素が1つだけであることを主張しています。これはまれです。より頻繁に、あなたがしたいことは、いくつかの動作をページ上のいくつかの要素に関連付けることです。その中には、多くのもの、1つまたはゼロが存在することがあります。
この場合、クリックしたときに画像を並べ替えることはほとんどありません。どのように動くべきかを計算するためのアルゴリズムはありませんが、ここではjQueryを使って同じことを達成するためのフレームワークを示します。
// create jQuery plugin for highlighting and shuffling brick dealies
(function($){
function expandify() {
var href = this.attr('href');
// create a popup containing the href
return this;
}
function shuffle() {
this.each(function(index, elem){
// calculate new position and move the element there.
});
return this;
}
$.fn.expandify = expandify;
$.fn.shuffle = shuffle;
})(jQuery);
// attaches behaviors to elements on the page after they've loaded
// either $.ready, or window onload, or after some ajaxing takes place
$('.wallBrick')
.click(function(e){
$(e.target)
.expandify();
$('.wallBrick')
.not(e.target)
.shuffle();
});