1

My script Code

$(function () {
    $(".ui-button-text").live("click", function () {
        var buttonName = $(this).text();
        if (buttonName == 'Continue') {
            $("#runloGc").prop("disabled", true);
        }
    });
});

Html code

  <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Cancel</span></button>
henrywright
  • 10,070
  • 23
  • 89
  • 150
jsduniya
  • 2,464
  • 7
  • 30
  • 45
  • live() is deprecated. – adeneo Jun 05 '13 at 13:21
  • This has been asked a millions times. [`.live`](http://api.jquery.com/live/) has beed REMOVED in jQuery 1.9. – Corneliu Jun 05 '13 at 13:24
  • 1
    It probably is "not working" because you are attaching to the click event of a span _inside_ a button, and the button click event is likely what gets fired/captured. – Tim Hobbs Jun 05 '13 at 13:35

3 Answers3

0

The .live() function is deprecated, try using .on():

$(function(){
    $(".ui-button-text").on("click",function(){
        var buttonName=$(this).text();
         if(buttonName == 'Continue'){
             $("#runloGc").prop("disabled",true);
         } 
     });
});

Or try like

$(function(){
    $("input[type='button']").on("click",".ui-button-text",function(){
        var buttonName=$(this).text();
         if(buttonName == 'Continue'){
             $("#runloGc").prop("disabled",true);
         } 
     });
});
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

You should use the following:

// New way (jQuery 1.7+) - .on(events, selector, handler)
$('#container').on('click', '.ui-button-text', function(event) {
    event.preventDefault();
    alert('testlink'); 
});

This will attach your event to any anchors within the #container element, reducing the scope of having to check the whole document element tree and increasing efficiency.

This is the best case scenario. If you are not sure about the container element, you can use the document then like:

$(document).on('click', '.ui-button-text', function(event) {

FIDDLE DEMO

palaѕн
  • 72,112
  • 17
  • 116
  • 136
0

As per your updated code, you should bind the event to the button not the span.

Demo

$(document).on('click', 'button.ui-button', function () {
 // code
});
Omar
  • 32,302
  • 9
  • 69
  • 112