Alon Shmiel
Alon Shmiel

Reputation: 7121

Remove all the onclick under TR

I want to remove all the onclicks 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

Answers (5)

Bud Damyanov
Bud Damyanov

Reputation: 31839

Try setting onclick attribute to empty string:

$("#current td").attr("onclick",""); 

Upvotes: 2

Somnath Kharat
Somnath Kharat

Reputation: 3610

Try this:

$("#current td").prop("disabled",true);

Upvotes: 1

Sachin
Sachin

Reputation: 40970

Use unbind() to remove a attached event handler from the element.

$( "#current td").unbind( "click" );

Upvotes: 2

Amit
Amit

Reputation: 15387

Try this

$("#current").each(function() {
   $(this).unbind("click");
});  

Reference

Upvotes: 1

St&#233;phane Bruckert
St&#233;phane Bruckert

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

Related Questions