Saurabh Sinha
Saurabh Sinha

Reputation: 1800

disable all previous created button except current one with jquery

I am using this delegated event handler function in jquery in my application. and its working fine.Now I want to desable all the button already created except current one.

How do i do that

$('#form').on('click', '.button', function(){
var temp = '<input type="button" class="button" />'
$('#form').append(temp);
})

Upvotes: 2

Views: 693

Answers (3)

kongaraju
kongaraju

Reputation: 9596

$('#form').on('click', '.button', function(){
    var temp = '<input type="button" class="button" />'
     $("#form").find(".button").prop("disabled",true).end().append(temp);
})

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Try

var $form = $('#form').on('click', '.button', function(){
    $form.find('.button').prop('disabled', true)
    var temp = '<input type="button" class="button" />'
    $form.append(temp);
})

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318518

After inserting the new button:

var temp = $('<input type="button" class="button" />');
$('#form').append(temp);
$('#form .button').not(temp).prop('disabled', true);

Please note that I added $() around the definition of the button so it's an element and not a HTML string (which would not work in .not()).

Alternatively you can also run this before inserting the button:

$('#form .button').prop('disabled', true);

That disables all buttons - but since the new one is not part of the form yet it won't be disabled

Upvotes: 4

Related Questions