Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select button with text using jQuery

Tags:

jquery

laravel

Is it possible to select buttons using the text property in jQuery?

I was trying like:

$.each(data, function(index, element){
    if(element.table_aval == 0)
    {
         var elmt = element.table_no;
         $('#table button[text='+elmt+']').css('color','red');
    }
});

Is this possible?

like image 518
Vishal B Avatar asked Feb 21 '26 09:02

Vishal B


1 Answers

The :contains selector allows you to select elements containing a specific string.

$(document).ready(function() {
  $('button:contains("Text")').css({'color': 'red'})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Text</button>

<button>Something Different</button>
like image 56
Brett DeWoody Avatar answered Feb 24 '26 06:02

Brett DeWoody