s1h4d0w
s1h4d0w

Reputation: 771

Disable onclick after click on <tr>

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

Answers (4)

rorymorris
rorymorris

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

Lee Jenkins
Lee Jenkins

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

shuskic
shuskic

Reputation: 81

Use the removeAttr function?

$("tr").click(function(){
    $(this).removeAttr("onclick");
});

Upvotes: 1

Aliou
Aliou

Reputation: 1105

Try removing the onclick attribute on all the trs instead of only the one being clicked:

$("tr").click(function() {
    $("tr").attr('onclick', '');
});

Upvotes: 2

Related Questions