選択リストに変換する必要がある UL LI のすべてのブロックに対して関数を記述するのではなく、関数を 1 回だけ使用しようとしています。私の作業コードはhttp://jsfiddle.net/qqzB5/にあります
私はこれを試しましたが、特定のセクション内のものだけでなく、すべてのliをループします:
$('.filterSection').each(function(){
$('<select class="locationFilterSelect" />').appendTo(this);
//Create Default option "Select One"
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Select One"
}).appendTo('select', this);
// Populate dropdown with menu items
$('li', this).each(function() {
var el = $(this);
$("<option />", {
"text" : el.text()
}).appendTo('select', this);
});
});