Reputation: 653
I am trying to change CSS of button using jquery, but i am not able to find the button using text property, my JQuery is:
$.ajax({
url : "{{url('booktable')}}",
type : "GET",
data : {},
success : function(data){
$.each(data, function(index, element){
if(element.table_aval == 0)
{
var elmt = element.table_no;
$('#table button[text='+elmt+']').css('color','red');
}
});
}
});
buttons are group of button created by foreach loops, thats why I am trying to find it using text attribute, how can i do that, buttons are:
<tbody>
@foreach($tables as $table)
<tr id="">
<!--input type="hidden" name="table_no" id="tno" value=""-->
<td style="text-align: center;">
<button class="btn" >{{$table->table_no}} </button>
</td>
</tr>
@endforeach
</tbody>
Upvotes: 0
Views: 2952
Reputation: 309
Maybe this code will help you: https://jsfiddle.net/auczzk5x/
You fill a text input with word: special or unspecial. And buttons below have text
atributte with value of one of these words. For example, if you type special and click Clorize Buttons than buttons with text="special"
will be in red color.
In your code above there is no HTML element with id="table"
, that you use in jQuery code: $('#table button[text='+elmt+']')
, what suggests that buttons are in element with id="table"
.
Upvotes: 1