Joe
Joe

Reputation: 610

how to select button by matching text inside a span

I want to disable a button which comes up in the dialog based on a condition. The problem is how do i access the button since its dynamically generated via the dialog ?

Generated html code in the dialog:

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="true">
    <span class="ui-button-text">Save</span>
</button>

Upvotes: 6

Views: 9948

Answers (4)

Rafay
Rafay

Reputation: 31033

for dynamic generation of DOM u can use .live()

Upvotes: 1

Michael O&#39;Loughlin
Michael O&#39;Loughlin

Reputation: 567

I assume there was a typo in your code and you didnt mean to close the opening span tag, so your code is

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="true">
    <span class="ui-button-text">Save</span>
</button>

Then you can change the word Save in the next line to whatever text is in the button you want to hide

$("button span:contains('Save')").parent().attr("disabled", true);

Upvotes: 14

bluish
bluish

Reputation: 27292

$("span:contains('Save')").parent().attr("disabled", true);

Upvotes: 0

Steve
Steve

Reputation: 50573

You could use JQuery to match on attributes:

$('button[role=button]').attr("disabled", true);

Upvotes: 0

Related Questions