動的に生成されたボタンのリストがあります...
var output="";
var active;
var x;
var i;
var user_id=localStorage.get('user_id');#
for(x=0;x<dynamic_count;x++)
{
output+="<div class='tbl' data-role='button' data-table_id='"+(x+1)+"'>";
output+="<p class='center_text'>"+(x+1)+</p>";
output+="<div>";
}
$('.table_holder').html(output).trigger('create');
//active and active_count come from AJAX request (I have missed this bit our of the code..active[0]=a table number where as active[1]= s user_id
for(i=0;i<active_count;i++)
{
if(active[1]==user_id)
{
$('.tbl').find("[data-table_id='"+active[0]+"']").css('backgroundColor', 'red');
}
}
残念ながら、これは目的の要素の背景色には影響しません。セレクター コードの問題なのか、css コードの問題なのか、jQuery Mobile の実装の問題なのかわかりません。
jQuery Mobile でスタイリングが必要な要素を動的に追加する場合、trigger('create')
メソッドを使用して css を適用する必要があることに気付きました。
これは明らかに元の jQuery css で修正された css を上書きします。