Reputation: 1800
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
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
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
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