My html is rendered like this:
<td colspan="2" onclick="reportTypeClick(this);" class="menuItem oneTest">...</td>
Now I want to disable/enable the td as well as the click event:
if(...) {
$('.oneTest').removeClass('menuItem').addClass('menuItemDisabled')
.attr('onclick', '');
} else {
$('.oneTest').removeClass('menuItemDisabled').addClass('menuItem')
.attr('onclick', 'reportTypeClick(this);');
}
The if works as expected, but the else doesn’t. That is to say, I get no script errors, but the event fails to fire.
Any ideas?
Looks like it has something to do with this.
You should remove the
onclickattribute and use jquery event handling..Alternatively you could alter your
reportTypeClickfunction..