Reputation: 771
I have a lot of table rows like:
<tr class="player" onclick="document.location = \'fight.php?fightplayer='.$rowselfight['name'].'\';">
All table rows have unique links. I now want to disable all the onclick
links after one of them has been clicked on. I tried editing a piece of code I found somewhere else:
$("tr").click(function() {
$(this).attr('onclick', '');
});
But it doesn't work, does anyone have an idea how to do this?
Upvotes: 1
Views: 6513
Reputation: 223
It sounds like you want to remove the onclick from every other element, once the original has been clicked? Or have I misunderstood the question? Try:
$("tr").click(function() {
$("tr").attr('onclick', '');
});
Upvotes: 0
Reputation: 2460
This question has been asked before. You want to remove the event handler from the HTML element. Please refer to: Best way to remove an event handler in jQuery?
Upvotes: 1
Reputation: 81
Use the removeAttr function?
$("tr").click(function(){
$(this).removeAttr("onclick");
});
Upvotes: 1
Reputation: 1105
Try removing the onclick
attribute on all the tr
s instead of only the one being clicked:
$("tr").click(function() {
$("tr").attr('onclick', '');
});
Upvotes: 2