Reputation: 7121
I want to remove all the onclick
s under specific tr
..
For example,
before:
<tr id="current">
<td onclick="foo();"></td>
<td onclick="foo();"><div onclick="abc();"></div></td>
<td onclick="foo();"></td>
<td onclick="foo();"></td>
</tr>
after:
<tr id="current">
<td></td>
<td><div></div></td>
<td></td>
<td></td>
</tr>
I think I have to do something like:
$("#current td").each(function() {
$(this).removeAttr('onclick');
});
$("#current td div").each(function() {
$(this).removeAttr('onclick');
});
but maybe there is another option.
Upvotes: 2
Views: 213
Reputation: 31839
Try setting onclick
attribute to empty string:
$("#current td").attr("onclick","");
Upvotes: 2
Reputation: 40970
Use unbind() to remove a attached event handler from the element.
$( "#current td").unbind( "click" );
Upvotes: 2
Reputation: 15387
Try this
$("#current").each(function() {
$(this).unbind("click");
});
Upvotes: 1
Reputation: 22903
Use .off()
$("#current").find("*").off();
find("*")
will find all the elements contained in #current
. This is then enough to remove all the onclick events (both <td>
and <div>
).
Upvotes: 5