Question

My buttons are input type=button, id field set, and no text in between the tags since it appears to the right of my buttons rather than inside. (sorry, won't let me publish the html for some reason).

I .button() them and set their label. All works as expected, but I can't select them by :contains().

How do you select jQuery UI buttons by their labels?

Thanks in advance!

Edit

I don't select by id because the text of the button changes based upon a variable in my db. Is there a way to select by .data?

Was it helpful?

Solution

You should create a button and look how jQuery creates it. When you look at the example in the documentation you see that .button() creates a span element in the button element that contains the label. So you can query on this inner span element which has a class of ui-button-text.

But I think that you should overthink your code and rework it so that you can select on the ID since they are made to identify things.

Edit: Then go for the first advice

var buttons = $('button').filter(function (index) {
    $('.ui-button-text:contains("' + your_string + '")', this).length > 0
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top