I have a list of buttons generated dynamically...
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');
}
}
Unfortunately this has no effect on the background color of the desired element. I am not sure whether it is a problem with my selector code, my css code, or a propblem with my implementation of jQuery Mobile.
I have noticed that when dynamically adding elements that need styling with jQuery Mobile I have needed to use the trigger('create') method to apply the css.
This obviously over writes any amended css with the original jQuery css.