Reputation: 2250
I have got this button <button id="beg" onclick"disable()">beg</button>
. And function is defined here
function disable(time){
$(this).attr('disabled', 'disabled');
};
Problem is that button doesn't get disabled, I have no idea why.
Thank you.
Upvotes: 1
Views: 114
Reputation: 337560
It's because this
in your function is not a reference to the button
element. Try this:
<button id="beg" onclick="disable(this)">beg</button>
function disable(el){
$(el).attr('disabled', 'disabled');
};
Or better yet, separate your HTML and JS completely by hooking up your event in JS:
<button id="beg">beg</button>
$('#beg').click(function() {
$(this).prop('disabled', true);
});
Upvotes: 7